练习课(一)

基本数据类型的赋值与运算

Eg1: public class Ex1{
       public static void main(String args []){
               boolean b = true ;
                  System.out.println(b);
         }
        }

       

Eg2: public class Ex2{
               public static void main(String args []){
                   char c = '晗';
                   System.out.println(c);
               }
        }

       

        Tips: 注意图中红色提示部分~~~

 

 

Eg3:  字面量(在代码中出现的形式)

         1.字面量为整数的 默认是整形(int)

         2.字面量为小数的 默认是双精度浮点型(double)

                  <1> 如何理解呢, float f = 0.1 ; 编译报错, 告知有可能损失精度

                         字面量是小数0.1, 但代表的双精度浮点型(double), 将double赋值给float有可能会损失精度

                         修改为 float f = 0.1F ; 即可

                  <2>int i = 0.5 * 10;

                         报错可能损失精度, 因为0.5

                 

posted @ 2014-05-15 16:01  Mirrorhanman  阅读(156)  评论(0编辑  收藏  举报