You are on page 1of 2

Java program to calculates the result of the expression `a % b`:

```java
import java.util.Scanner;

public class ModuloCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input the values for a and b


System.out.print("Enter the value for a: ");
int a = scanner.nextInt();

System.out.print("Enter the value for b: ");


int b = scanner.nextInt();

// Calculate the result of the expression a % b


int result = a % b;

// Display the result


System.out.println("Result of " + a + " % " + b + " is: " + result);

// Close the scanner


scanner.close();
}
}
```

This program prompts the user to input values for variables `a` and `b`, calculates the result
of the expression `a % b`, and then prints the result.
Certainly! The expression `a /= b` is equivalent to `a = a / b`. Below is a simple Java program
that takes input for variables `a` and `b`, performs the division operation, and assigns the
result back to `a`. This program prints the result after the operation:
import java.util.Scanner;

public class DivisionAssignment {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Input the values for a and b


System.out.print("Enter the value for a: ");
int a = scanner.nextInt();

System.out.print("Enter the value for b: ");


int b = scanner.nextInt();

// Perform the division assignment: a /= b


a /= b;

// Display the result


System.out.println("Result of a /= b is: " + a);

// Close the scanner


scanner.close();
}
}
```

This program will take the values for `a` and `b` as input, perform the division assignment
`a /= b`, and then print the updated value of `a`.

You might also like