123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
-
- import java.util.Scanner;
-
- public class ShortCalculator {
-
- public static void main(String[] args){
- //Create scanner to recieve user input
- Scanner input = new Scanner(System.in);
-
- //Collects user input for numbers
- System.out.println("Please Enter First Number: Between 1 - 65535");
- int num1a = input.nextInt();
- short num1 = (short)num1a;
-
- System.out.println("Please Enter Second Number: Between 1- 65535 ");
- int num2a = input.nextInt();
- short num2 = (short)num2a;
-
- //Create scanner to recieve operator
- Scanner operator = new Scanner(System.in);
- System.out.println("Please Choose An Operation (+, -, *, //, or %)");
-
- String op = operator.nextLine();
-
- //Create variable to hold result of math operation
- short result = 0;
- //Swtich statment showing math operations for cases based on operator
-
- switch(op) {
- case "+" : result = (short)(num1 + num2);
- break;
- case "-" : result = (short)(num1 - num2);
- break;
- case "*" : result = (short)(num1 * num2);
- break;
- case "//" : result = (short)(num1 / num2);
- break;
- case "%" : result = (short)(num1 % num2);
- break;
- default: System.out.print("Invalid Operator, Please Choose Another!");
- break;
- }
-
- System.out.println(num1 + " " + op + " " + num2 + " = " + result);
-
-
- }
-
-
-
-
- }
-
-
-
|