ShortCalculator.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import java.util.Scanner;
  2. public class ShortCalculator {
  3. public static void main(String[] args){
  4. //Create scanner to recieve user input
  5. Scanner input = new Scanner(System.in);
  6. //Collects user input for numbers
  7. System.out.println("Please Enter First Number: Between 1 - 65535");
  8. int num1a = input.nextInt();
  9. short num1 = (short)num1a;
  10. System.out.println("Please Enter Second Number: Between 1- 65535 ");
  11. int num2a = input.nextInt();
  12. short num2 = (short)num2a;
  13. //Create scanner to recieve operator
  14. Scanner operator = new Scanner(System.in);
  15. System.out.println("Please Choose An Operation (+, -, *, //, or %)");
  16. String op = operator.nextLine();
  17. //Create variable to hold result of math operation
  18. short result = 0;
  19. //Swtich statment showing math operations for cases based on operator
  20. switch(op) {
  21. case "+" : result = (short)(num1 + num2);
  22. break;
  23. case "-" : result = (short)(num1 - num2);
  24. break;
  25. case "*" : result = (short)(num1 * num2);
  26. break;
  27. case "//" : result = (short)(num1 / num2);
  28. break;
  29. case "%" : result = (short)(num1 % num2);
  30. break;
  31. default: System.out.print("Invalid Operator, Please Choose Another!");
  32. break;
  33. }
  34. System.out.println(num1 + " " + op + " " + num2 + " = " + result);
  35. }
  36. }