33
44public final class Main {
55 // Stores all conversion factors with 'seconds' as the base unit.
6- private static final Map <String , Integer > map = Map .of (
7- "year" , 31557600 ,
8- "month" , 2629800 , // Note: This is an average month
9- "week" , 604800 ,
10- "day" , 86400 ,
11- "hour" , 3600 ,
12- "min" , 60 ,
13- "sec" , 1
6+ private static final Map <String , Long > map = Map .of (
7+ "century" , 3155760000L , //Long literal for large numbers 'L' suffix has been added [otherwise error arises]
8+ "decade" , 315576000L ,
9+ "year" , 31557600L ,
10+ "month" , 2629800L , // Note: This is an average month
11+ "week" , 604800L ,
12+ "day" , 86400L ,
13+ "hour" , 3600L ,
14+ "min" , 60L ,
15+ "sec" , 1L
1416 );
1517
1618 public static void main (String [] args )
@@ -21,7 +23,7 @@ public static void main(String[] args)
2123 {
2224
2325 System .out .println ("=== Duration Converter ===" );
24- System .out .println ("Supported units: year, month, week, day, hour, min, sec." );
26+ System .out .println ("Supported units: century, decade, year, month, week, day, hour, min, sec." );
2527 System .out .println ("Enter duration, from_unit, and to_unit (e.g., 2 hour min):" );
2628 final long duration = sc .nextLong ();
2729 final String from = sc .next ().toLowerCase ();
@@ -37,7 +39,7 @@ public static void main(String[] args)
3739 System .out .println (duration + " " + from + " = " + result + " " + to );
3840 } catch (Exception e )
3941 {
40- System .err .println ("Invalid input. Please enter a number followed by two units." );
42+ System .err .println ("Invalid input. Please enter a number followed by two units as per given instruction ." );
4143 }
4244 }
4345}
0 commit comments