// Hier geht es um Wertebereiche und Zuweisungskompatibilität public class Uebung05_a2 { public static void main(String[] args) { // Maximale byte, short, int, long-Zahl ausgeben. // Hierfür gibt es Konstanten in den Java-Klassen // Byte, Short, Integer, Long. byte b = Byte.MAX_VALUE; short s = Short.MAX_VALUE; int i = Integer.MAX_VALUE; long l = Long.MAX_VALUE; System.out.println("Max Byte: " + b); System.out.println("Max Short: " + s); System.out.println("Max Integer: " + i); System.out.println("Max Long: " + l); b = Byte.MIN_VALUE; s = Short.MIN_VALUE; i = Integer.MIN_VALUE; l = Long.MIN_VALUE; System.out.println("Min Byte: " + b); System.out.println("Min Short: " + s); System.out.println("Min Integer: " + i); System.out.println("Min Long: " + l); l = Long.MAX_VALUE + 1; System.out.println("Max Long + 1 = " + l); // Andere Möglichkeit, die "Maximalzahl" zu ermitteln: // wir schieben das erste Bit an die höchste Stelle // (Byte: Bit 7, 1<<7) und bilden dann das Komplement (~) b = (byte)~((byte)1<<7); System.out.println(b); // Probleme bei der Zuweisung! Wo und warum? int z1 = 0; long z2 = 1000; // Problem: Zuweisung long an int nicht erlaubt! // z1 = z2; // Problem: Zuweisung von double an float nicht erlaubt! // float z3 = 1.0; // Eine int-Konstante: 1000 // Eine long-Konstante: 1000L // Eine double-Konstante: 1000.0 // Eine float-Konstante: 1000.0F (!!!) } }