ShortCalculator.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3. public class ShortCalculator {
  4. public static Short add(short number1,short number2){
  5. Scanner scanner = new Scanner(System.in);
  6. System.out.println("Enter the first number");
  7. number1 = scanner.nextShort();
  8. System.out.println("Enter second number");
  9. number2 = scanner.nextShort();
  10. short add = (short)(number1 + number2);
  11. System.out.println(add);
  12. return add;
  13. }
  14. public static Short subtract(short number1,short number2){
  15. Scanner scanner = new Scanner(System.in);
  16. System.out.println("Enter the first number");
  17. number1 = scanner.nextShort();
  18. System.out.println("Enter second number");
  19. number2 = scanner.nextShort();
  20. short subtract = (short)(number1 - number2);
  21. System.out.println(subtract);
  22. return subtract;
  23. }
  24. public static Short multiply(short number1,short number2){
  25. Scanner scanner = new Scanner(System.in);
  26. System.out.println("Enter the first number");
  27. number1 = scanner.nextShort();
  28. System.out.println("Enter second number");
  29. number2 = scanner.nextShort();
  30. short multiply = (short)(number1 * number2);
  31. System.out.println(multiply);
  32. return multiply;
  33. }
  34. public static Short divide(short number1,short number2){
  35. Scanner scanner = new Scanner(System.in);
  36. System.out.println("Enter the first number");
  37. number1 = scanner.nextShort();
  38. System.out.println("Enter second number");
  39. number2 = scanner.nextShort();
  40. short divide = (short)(number1/number2);
  41. System.out.println(divide);
  42. return divide;
  43. }
  44. }