Java Program to get minimum 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 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:

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

Minimum Value = 2
Java Program to get maximum of three integer values
How to convert byte to string in Java
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment