JAVAデータ型変換の詳細

2545 ワード

public class thirteen {
    public static void  main(String[] str){
        System.out.println("      ");
        //             
        //1.      
        //                                  
        // byte 、char 、 short --> int --> long -->float --> double
        //  byte 、char 、 short               int   
        byte b1=12;
        int i2=13;
        int i3=b1+i2;
        System.out.println(i3);
        short s1 =153;
        double d1=s1;
        System.out.println(d1);
        /************   *****************/
        // char            
        char c1 ='a'; //97
        int i4=10;
        int i5=c1+i4;
        System.out.println(i5);
        short s3= 10;
        //char c3 =c1+s3; //     
        // short s4= c1+s3; //     

        //2.                  
        //         : ()
        //                
        double d6 =12.3;
       // int i7 = d6; //    
        //           int  
        int i7 =(int)d6;
        //                           
        //       
        System.out.println(i7);
        //            
        long l1 =123;
        short s8 = (short) l1;
        System.out.println(s8);
        //             short           
        //                           
        int i0=129;
        byte b12= (byte) i0;
        System.out.println(b12);
        //long           l
        //                   int
        long l12=123456;
        System.out.println(l12);
        //   long          L

        //************
        //   1
        //            f
        float f12= 12.3f;
        System.out.println(f12);

       //   2
        byte b =12;
        //              int 
        //              double  
       //  byte b123=b+1;     
       // float f123= b + 123.2;    

        //      String
        //          
        //           
        // String                   
        //        String
        int number=100;
        String numberStr= "  :";
        String str1= numberStr+number;
        System.out.println(str1);
        //  
        char c ='a'; // 97
        int num =10;
        String str2= "hello";
        System.out.println(c+num+str2); // 107hello
        System.out.println(c+str2+num); //ahello10
        System.out.println(c+(str2+num)); // a10hello
        System.out.println((c+str2)+num); // ahello10

        //  2
        // *    *
        String Str1="*";
        char t='\t';
        System.out.println(Str1+t+Str1);

        //                          
    }
}