English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Display at least three integer values in Java

The following is an example of displaying the smallest value among three integer values.

Example

public class Demo {
   public static void main(String[] args) {
      int val1 = 99;
      int val2 = 87;
      int val3 = 130;
      System.out.println("Number 1 =+val1);
      System.out.println("Number 2 =+val2);
      System.out.println("Number 3 =+val3);
      if (val2 < val1) {
         val1 = val2;
      }
      if (val3 < val1) {
         val1 = val3;
      }
      System.out.println("The smallest of three numbers: "+val1);
   }
}

Output Result

Number 1 = 99
Number 2 = 87
Number 3 = 130
The smallest of three numbers: 87

In the above program, we use three integer variables and compare them.

int val1 = 99;
int val2 = 87;
int val3 = 130;

Now use conditional checks to determine which integer value is the smallest.

if (val2 < val1) {
   val1 = val2;
}
if (val3 < val1) {
   val1 = val3;
}

Return the minimum value above.