18 Aug Java Program to get maximum of three integer values
Declare and initialize three integer variables:
// 3 integers int p = 2; int q = 5; int r = 3;
Now, we will check for maximum value from the above three integers. Use the greater than (>) and less than (<) Relational operator for comparison as in the below example.
Example
Following is how to get maximum value from three integer values in Java:
public class Example {
public static void main(String[] args) {
// 3 integers
int p = 2;
int q = 5;
int r = 3;
// checking for maximum value
if (q > p) {
p = q;
}
if (r > p) {
p = r;
}
// displaying maximum from three integers
System.out.println("Maximum Value = "+p);
}
}
Output
Maximum Value = 5
No Comments