ShortCalculator.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Write a program that reads in two numbers between 0 and 65535,
  2. //stores them in short variables, and computes their unsigned sum,
  3. //difference, product, quotient, and remainder , without converting
  4. //them to int.
  5. import java.util.*;
  6. public class ShortCalculator {
  7. short f;
  8. short s;
  9. public ShortCalculator(){
  10. short first = f;
  11. short second = s;
  12. }
  13. public static void main(String[] args){
  14. Scanner shortNum = new Scanner(System.in);
  15. System.out.println("Enter first short");
  16. short f = shortNum.nextShort();
  17. System.out.println("Enter second short");
  18. short s = shortNum.nextShort();
  19. ShortCalculator shortCalc = new ShortCalculator();
  20. shortCalc.getSum(f, s);
  21. shortCalc.getDifference(f, s);
  22. shortCalc.getProduct(f, s);
  23. shortCalc.getQuotient(f, s);
  24. shortCalc.getRemainder(f, s);
  25. }
  26. public short getSum(short first,short second){
  27. short sum = (short)(first + second);
  28. System.out.println("sum is "+ sum);
  29. return sum;
  30. }
  31. public short getDifference(short first,short second){
  32. short difference = (short)(first - second);
  33. System.out.println("differece is "+ difference);
  34. return difference;
  35. }
  36. public short getProduct(short first,short second){
  37. short product = (short)(first * second);
  38. System.out.println("product is "+ product);
  39. return product;
  40. }
  41. public short getQuotient(short first,short second){
  42. short quotient = (short)(first / second);
  43. System.out.println("quotient is "+ quotient);
  44. return quotient;
  45. }
  46. public short getRemainder(short first,short second){
  47. short remainder = (short)(first % second);
  48. System.out.println("remainder is "+ remainder);
  49. return remainder;
  50. }
  51. }