fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static String months[];
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. months = new String[13];
  15. months[0] = null ;
  16. months[1] = "January";
  17. months[2] = "February";
  18. months[3] = "March";
  19. months[4] = "April";
  20. months[5] = "May";
  21. months[6] = "June";
  22. months[7] = "July";
  23. months[8] = "August";
  24. months[9] = "September";
  25. months[10] = "October";
  26. months[11] = "November";
  27. months[12] = "December";
  28.  
  29. System.out.println( "DEBUG args: " + Arrays.toString( args ) );
  30. if( args.length == 0 ) {
  31. System.out.println( "No month specified. No arguments passed to 'main' method." );
  32. } else if ( args.length == 1 ) { // Else we have a single argument as expected.
  33. int m = Integer.parseInt( args[0] );
  34. System.out.println( months[ m ] );
  35. } else if ( args.length > 1 ) { // Else we have multiple arguments, but expected only one.
  36. System.out.println( "ERROR - more than one argument passed to 'main' method." );
  37. } else { // Else impossible. Should not reach this point. Defensive programming.
  38. System.out.println( "ERROR - Unexpectedly reached IF-ELSE. Should be impossible." );
  39. }
  40.  
  41. }
  42. }
Success #stdin #stdout 0.05s 4386816KB
stdin
5 8 9
stdout
DEBUG args: []
No month specified. No arguments passed to 'main' method.