Imprimer les limites des types primitifs en Java
Le langage de programmation Java est un langage fortement typé et se compose de huit types de données primitifs(byte, short, int, long, float, double, boolean, char). Pour en savoir plus sur le type de données primitif java, veuillez visiterhttp://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
Eh bien, parfois, nous avons vraiment besoin de savoir quelle est la limite des types primitifs en java. Avec le code simple suivant, nous pouvons afficher la limite de chacun des types de données primitifs java (sauf boolean et char) :)
public class PrintTypeLimit { public static void main(String args[]) { System.out.println("Min byte value = " + Byte.MIN_VALUE); System.out.println("Max byte value = " + Byte.MAX_VALUE); System.out.println("Min short value = " + Short.MIN_VALUE); System.out.println("Max short value = " + Short.MAX_VALUE); System.out.println("Min int value = " + Integer.MIN_VALUE); System.out.println("Max int value = " + Integer.MAX_VALUE); System.out.println("Min long value = " + Long.MIN_VALUE); System.out.println("Max long value = " + Long.MAX_VALUE); System.out.println("Min float value = " + Float.MIN_VALUE); System.out.println("Max float value = " + Float.MAX_VALUE); System.out.println("Min double value = " + Double.MIN_VALUE); System.out.println("Max double value = " + Double.MAX_VALUE); } }
[.souligner]##
Sortie
Min byte value = -128 Max byte value = 127 Min short value = -32768 Max short value = 32767 Min int value = -2147483648 Max int value = 2147483647 Min long value = -9223372036854775808 Max long value = 9223372036854775807 Min float value = 1.4E-45 Max float value = 3.4028235E38 Min double value = 4.9E-324 Max double value = 1.7976931348623157E308