Java数据类型+练习

java基础数据类型:

         四类八种:

                   1, 整数型

                            byte   2的8次方(取值范围--<-128~127>)--1个字节

                            short   2的16次方--2个

                            int   2的32次方--4个

                            long   2的64次方--8个

                   2, 浮点型

                            float 小数点后面7位--4个

                            double      小数点后面11位--8个

                   3, 布尔型

                            boolean(只有两个值, true, false)--1个

                   4, 字符型

                            char--2个字节

                  字符串

                            String

         int a = 5;

                   全部存到栈

         引用类型:String s = "abc";

                   所有的类

                   所有的数组

                   所有的接口

 

**变量赋值练习(//后为正确写法):

                   int a, b, c;

                   a = 2;

                   b = 'q';

       

      

                   c = 4;

                   char d = '5';

                   byte e;

                   e = a + b;        //e = (byte)( a + b );

                       

       

 

                           

                   boolean f = true;

                   double g = 4.3;

                   g += b;             //+= -= 之类都是在后台运算不需要改值的类型

                        

        

 

                   b += 0.3;         //+= -= 之类都是在后台运算不需要改值的类型

                   b = b + 0.3;       //b = (int)(b + 0.3)

                   c += f ? 2 : 4;

                   float h = 12.4;  //float h = 12.4f;

                   float i = 14.2;   //float h = 14.2f;

                   e = h + i;            //e = (byte)( h + i ); float相加只取整数相加,无四舍五入算法

                       

       

 

                   e += h;               //+= -= 之类都是在后台运算不需要改值的类型

                   a += 2147483646;    //int取值范围-2147483648到2147483647

//a+2147483646之后为2147483648,超出int取值范围1位,则从取值范围最小即-2147483648开始取一位得到最终答案为-2147483648

                        

               

                                    

                   float j = h / 0.5;         //float j = (float)( h / 0.5 );

posted @ 2017-07-13 16:26  Oo。  阅读(291)  评论(0编辑  收藏  举报