To get the maximum or minimum of two numbers in Java, you can use the Math.max() and Math.min() methods respectively.
Here are examples:
To get the maximum of two numbers:
int a = 10;
int b = 20;
int max = Math.max(a, b);
System.out.println("Maximum of " + a + " and " + b + " is " + max);
Output: Maximum of 10 and 20 is 20
To get the minimum of two numbers:
int a = 10;
int b = 20;
int min = Math.min(a, b);
System.out.println("Minimum of " + a + " and " + b + " is " + min);
Output: Minimum of 10 and 20 is 10
In both cases, the Math.max() and Math.min() methods take two parameters and return the maximum or minimum value respectively.