Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- + addition
- - subtraction
- * multiplication
- / division
- % modulo
- */
- public class Operation {
- public static void main(String[] args) {
- int intX = 10;
- int intY = 5;
- int intZ = 20;
- double doubleD = 2.5;
- int sum = intX + intY; // Addition
- int difference = intX - intY; // Subtraction
- int product = intX * intY; // Multiplication
- int quotient = intX / intY; // Division
- int remainder = intY % intX; // Modulo (remainder)
- System.out.println("Sum: " + sum);
- System.out.println("Difference: " + difference);
- System.out.println("Product: " + product);
- System.out.println("Quotient: " + quotient);
- System.out.println("Remainder: " + remainder);
- //int divideZero = intX / 0; //Error if you uncomment this line
- int remainderDiscarded = intX / intZ; // Result is 0 while answer in real life is 0.5
- double sumIntAndDouble = intX + doubleD; // x is an integer but the output will be a double
- double quotientWithDecimal = intX / doubleD; // Division With Decimal
- System.out.println();
- System.out.println("Quotient, Remainder Discarded: " + remainderDiscarded);
- System.out.println("Sum Int And Double: " + sumIntAndDouble);
- System.out.println("Quotient with decimal: " + quotientWithDecimal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment