Skip to content

Instantly share code, notes, and snippets.

@cgmb
Created February 2, 2015 23:26
Show Gist options
  • Save cgmb/ab9cfe2def9c9c72079b to your computer and use it in GitHub Desktop.
Save cgmb/ab9cfe2def9c9c72079b to your computer and use it in GitHub Desktop.
An adding calculator in Java
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