Guest User

Untitled

a guest
Apr 26th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. /*
  2. + addition
  3. - subtraction
  4. * multiplication
  5. / division
  6. % modulo
  7. */
  8. public class Operation {
  9. public static void main(String[] args) {
  10. int intX = 10;
  11. int intY = 5;
  12. int intZ = 20;
  13. double doubleD = 2.5;
  14.  
  15. int sum = intX + intY; // Addition
  16. int difference = intX - intY; // Subtraction
  17. int product = intX * intY; // Multiplication
  18. int quotient = intX / intY; // Division
  19. int remainder = intY % intX; // Modulo (remainder)
  20.  
  21. System.out.println("Sum: " + sum);
  22. System.out.println("Difference: " + difference);
  23. System.out.println("Product: " + product);
  24. System.out.println("Quotient: " + quotient);
  25. System.out.println("Remainder: " + remainder);
  26.  
  27. //int divideZero = intX / 0; //Error if you uncomment this line
  28. int remainderDiscarded = intX / intZ; // Result is 0 while answer in real life is 0.5
  29. double sumIntAndDouble = intX + doubleD; // x is an integer but the output will be a double
  30. double quotientWithDecimal = intX / doubleD; // Division With Decimal
  31.  
  32. System.out.println();
  33. System.out.println("Quotient, Remainder Discarded: " + remainderDiscarded);
  34. System.out.println("Sum Int And Double: " + sumIntAndDouble);
  35. System.out.println("Quotient with decimal: " + quotientWithDecimal);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment