Last active
May 9, 2017 21:26
-
-
Save mhornbacher/2beb02cd388fef616a5adc49690e6301 to your computer and use it in GitHub Desktop.
Help for Catastrophiq on Silicon Discourse
This file contains hidden or 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
import java.util.Scanner; | |
import java.util.InputMismatchException; | |
import java.lang.Math; | |
public class AddNumbers { | |
public static void main(String[] args) { | |
Scanner reader = new Scanner(System.in); | |
System.out.println("Please enter two numbers:"); | |
try{ | |
System.out.print("A: "); | |
long num1 = reader.nextLong(); | |
System.out.print("B: "); | |
long num2 = reader.nextLong(); | |
//perform the operations | |
long addition = num1 + num2; | |
long multiplacation = num1 * num2; | |
long division = num1 / num2; | |
long remainder = num1 % num2; | |
double power = Math.pow(num1, num2); | |
String output = String.format( | |
"A + B = %d\nA * B = %d\nA / B = %d remainder %d\nA ^ B = %6.2e" , | |
addition, multiplacation, division, remainder, power); | |
System.out.println(output); | |
} catch (InputMismatchException e) { | |
System.out.println("Invalid Input"); | |
} | |
reader.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment