Pin It

How get and use minimum and maximum values of primitive data types through Java program ?.

Program to demonstrate how get and use minimum and maximum values of primitive data types in Java.

package com.hubberspot.primitive.examples;

public class MinimumAndMaximumDemo {

 public static void main(String[] args) {

  // Create a Byte object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant
  Byte minimumByteValue = Byte.MIN_VALUE;
  Byte maximumByteValue = Byte.MAX_VALUE;

  System.out.println("Minimum byte value is : " + minimumByteValue);
  System.out.println("Maximum byte value is : " + maximumByteValue);

  // Create a Short object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant
  Short minimumShortValue = Short.MIN_VALUE;
  Short maximumShortValue = Short.MAX_VALUE;

  System.out.println("Minimum short value is : " + minimumShortValue);
  System.out.println("Maximum short value is : " + maximumShortValue);

  // Create an Integer object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant  
  Integer minimumIntegerValue = Integer.MIN_VALUE;
  Integer maximumIntegerValue = Integer.MAX_VALUE;

  System.out.println("Minimum integer value is : " + minimumIntegerValue);
  System.out.println("Maximum integer value is : " + maximumIntegerValue);

  // Create a Long object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant
  Long minimumLongValue = Long.MIN_VALUE;
  Long maximumLongValue = Long.MAX_VALUE;

  System.out.println("Minimum long value is : " + minimumLongValue);
  System.out.println("Maximum long value is : " + maximumLongValue);

  // Create a Float object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant
  Float minimumFloatValue = Float.MIN_VALUE;
  Float maximumFloatValue = Float.MAX_VALUE;

  System.out.println("Minimum float value is : " + minimumFloatValue);
  System.out.println("Maximum float value is : " + maximumFloatValue);

  // Create a Double object holding minimum
  // and maximum value of byte primitive
  // In order to get minimum and maximum value
  // we use Wrapper classes MAX_VALUE and MIN_VALUE constant
  Double minimumDoubleValue = Double.MIN_VALUE;
  Double maximumDoubleValue = Double.MAX_VALUE;

  System.out.println("Minimum double value is : " + minimumDoubleValue);
  System.out.println("Maximum double value is : " + maximumDoubleValue);

 }

}



Output of the program : 


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot