|
|
back to boardJava Program: import java.io.PrintWriter; import java.util.Scanner; public class Sum { public static void main ( String [] args ) { /** * Initialize */ Scanner inputs = null; PrintWriter output = null; try { if ( args != null && args.length == 2 ) { /** * Read Inputs */ inputs = new Scanner ( System.in ); /** * For Printing Output */ output = new PrintWriter ( System.out ); Integer a = inputs.nextInt (); Integer b = inputs.nextInt (); output.println ( a + b ); } else { System.out.println ( "Only 2 Integer values are accepted as input" ); } } catch ( Exception e ) { System.out.println ( "There is an error while executing this program : " + e ); } finally { if ( inputs != null ) inputs.close (); if ( output != null ) { output.flush (); output.close (); } } } } You don't really need to check for amount of arguments, you just need to read what you're asked for. Attempt to do this simplier, without try-catch-finally construction. |
|
|