Syntax error Java program to get the minimum of three long values

Java program to get the minimum of three long values



Firstly, let us declare and initialize three long values.

long val1 = 88799;
long val2 = 98567;
long val3 = 98768;

Now, find the minimum of three long values using the following condition −

// checking for maximum
if (val2 < val1) {
   val1 = val2;
}
if (val3 < val1) {
   val1 = val3;
}

The following is the complete example to get the minimum value −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      long val1 = 88799;
      long val2 = 98567;
      long val3 = 98768;
      // displaying
      System.out.println("Number 1 = "+val1);
      System.out.println("Number 2 = "+val2);
      System.out.println("Number 3 = "+val3);
      // checking for maximum
      if (val2 < val1) {
         val1 = val2;
      }
      if (val3 < val1) {
         val1 = val3;
      }
      System.out.println("The minimum of three numbers: "+val1);
   }
}

Output

Number 1 = 88799
Number 2 = 98567
Number 3 = 98768
The minimum of three numbers: 88799
Updated on: 2019-07-30T22:30:24+05:30

98 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements