Created
February 2, 2015 23:26
-
-
Save cgmb/ab9cfe2def9c9c72079b to your computer and use it in GitHub Desktop.
An adding calculator in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Add { | |
public static void main(String[] args) { | |
if (args.length != 2) { | |
System.err.println("Add can only add two numbers!"); | |
System.exit(1); | |
} | |
int a = 0; | |
int b = 0; | |
try { | |
a = Integer.parseInt(args[0]); | |
b = Integer.parseInt(args[1]); | |
} catch (NumberFormatException e) { | |
System.err.println("Add requires integer arguments"); | |
System.exit(2); | |
} | |
int c = a + b; | |
System.out.println(Integer.toString(c)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment