Due Date: March 4, 2024
Modulus of 3's
/* Instructions:
* Return true if the given non-negative number is
* a multiple of 3 or a multiple of 5.
*
* Use the % "mod" operator
*
* or35(3) → true
* or35(10) → true
* or35(8) → false
*
* Note: your value for this exercise will be different based on your seat number
*/
remainder 3 - Click here.
public class MathOperatorsDemo {
public static void main(String[] args) {
// Declare variables
int a = 10;
int b = 5;
// Addition
int addition = a + b;
System.out.println("Addition: " + a + " + " + b + " = " + addition);
// Subtraction
int subtraction = a - b;
System.out.println("Subtraction: " + a + " - " + b + " = " + subtraction);
// Multiplication
int multiplication = a * b;
System.out.println("Multiplication: " + a + " * " + b + " = " + multiplication);
// Division
int division = a / b;
System.out.println("Division: " + a + " / " + b + " = " + division);
// Modulus (remainder)
int modulus = a % b;
System.out.println("Modulus: " + a + " % " + b + " = " + modulus);
// Unary minus and plus
int unaryMinus = -a;
int unaryPlus = +b; // Generally, this does not change the value
System.out.println("Unary Minus: -" + a + " = " + unaryMinus);
System.out.println("Unary Plus: +" + b + " = " + unaryPlus);
// Increment operators
int preIncrement = ++a; // Increments a by 1, then returns a
int postIncrement = b++; // Returns b, then increments b by 1
System.out.println("Pre-Increment: ++a = " + preIncrement);
System.out.println("Post-Increment: b++ = " + postIncrement + " (b becomes " + b + " after operation)");
// Decrement operators
int preDecrement = --a; // Decrements a by 1, then returns a
int postDecrement = b--; // Returns b, then decrements b by 1
System.out.println("Pre-Decrement: --a = " + preDecrement);
System.out.println("Post-Decrement: b-- = " + postDecrement + " (b becomes " + b + " after operation)");
}
}