package workshop.tag2;

public class Gruppe2 {

    public static void main(String[] args) {
        // Aufgabe 1: Wandle int in short um
        int i = 100;
        short s = (short) i; // Typecast
        System.out.println("[Integer->Short] Integer: " + i);
        System.out.println("[Integer->Short] Short: " + s);

        // Achtung: Kann zu Datenverlust führen. Short hat Wertebereich -32.768 bis +32.767, Integer -2.147.483.648 bis +2.147.483.647
        i = 32768;
        s = (short) i;
        System.out.println("[Integer->Short] Integer: " + i);
        System.out.println("[Integer->Short] Short: " + s);


        // Aufgabe 2: Wandle double in int um
        double d = 3.999;
        int di = (int) d;
        System.out.println("[Double->Integer] Double: " + d);
        System.out.println("[Double->Integer] Integer: " + di);


        // Aufgabe 3: Code-Beispiel
        aufgabe3();
    }


    private static void aufgabe3() {
        int i = 5;
        long l = i; // implizite Typumwandlung (kein Typecast notwendig), da Wertebereich long > Wertbereich int

        double d = 3.3;
        float f = (float) d; // explizite Typumwandlung (Typecast) notwendig, da Wertebereich float < Wertebereich double; Kann zu Datenverlust führen

        System.out.println("[Aufgabe3] i: " + i);
        System.out.println("[Aufgabe3] l: " + l);
        System.out.println("[Aufgabe3] d: " + d);
        System.out.println("[Aufgabe3] f: " + f);
    }

}
