Display Minimum and Maximum values of datatype int in Java

Java 8Object Oriented ProgrammingProgramming

To get the minimum value of datatype int in Java, use the following −

Integer.MIN_VALUE

To get the maximum value of datatype int in Java, use the following −

Integer.MAX_VALUE

Let us now implement this in our example.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      int val1 = 20;
      int val2 = 3000;
      System.out.println("Value1: "+val1);
      System.out.println("Value2: "+val2);
      System.out.println("Maximum value: "+Integer.MIN_VALUE);
      System.out.println("Minimum value: "+Integer.MAX_VALUE);
   }
}

Output

Value1: 20
Value2: 3000
Maximum value: -2147483648
Minimum value: 2147483647
raja
Published on 12-Nov-2018 10:40:20
Advertisements