19 Aug Java Program to get minimum of three integer values
Declare and initialize three integer variables:
1 2 3 4 5 6 |
// 3 integers int p = 2; int q = 5; int r = 3; |
Now, we will check for minimum 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 minimum value from three integer values in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class Example { public static void main(String[] args) { // 3 integers int p = 2; int q = 5; int r = 3; // checking for minimum value if (q < p) { p = q; } if (r < p) { p = r; } // displaying minimum from three integers System.out.println("Minimum Value = "+p); } } |
Output
1 2 3 |
Minimum Value = 2 |
No Comments