Basic data basic knowledge of Java (ii) type conversion

public  class test_20190923 { 

    public  static  void main (String ... AS) {
         // basic types of low accuracy to accurately convert the implicit conversion to a low precision accuracy explicit conversion
         // 1.byte to the any 
        byte B =. 1 ;
         Short = S B;
         int I = B;
         Long L = B;
         a float F = B;
         Double D = B; 

        // 2.short to the any 
        Short S2 =. 1 ;
         byte B2 = ( byte ) S2;
         int I2 = s2;
        long l2 = s2;
        float f2 = s2;
        double d2 = s2;

        // 3.int to any
        int i3 = 1;
        byte b3 = (byte) i3;
        short s3 = (short) i3;
        long l3 = i3;
        float f3 = i3;
        double d3 = i3;

        // 4.long to any
        long l4 = 1l;
        byte b4 = (byte) l4;
        short s4 = (short) l4;
        int i4 = (int) l4;
        float f4 = l4;
        double d4 = l4;

        // 5.float to any
        float f5 = 1.0f;
        byte b5 = (byte) f5;
        short s5 = (short) f5;
        int i5 = (int) f5;
        long l5 = (long) f5;
        double d5 = f5;

        // 6.double to any
        double d6 = 1.00d;
        byte b6 = (byte) d6;
        short s6 = (short) d6;
        int i6 = (int) d6;
        long l6 = (long) d6;
        float f6 = (float) d6;

        // 7.char to any
        char c7 = 'a';
        byte b7 = (byte) c7;
        short s7 = (short) c7;
        int i7 = c7;
        long l7 = c7;
        float f7 = c7;
        double d7 = c7;

    }
}

 

Guess you like

Origin www.cnblogs.com/liw66/p/11576449.html