Java basic grammar (on) |
Content Outline
|
① class within and outside the method declaration: Member variables ② Method inner body: local variables
①long num = 123445678L; add back "L" ②double a = 0:11; ③float num = 0.11F; add back "F"
①Java picked in a Unicode encoding, you may store a letter characters, a character other languages ② char c1 = 'a'; char c2 = '中'; char c3 = '9'; ③ 可存储转义字符,如 char c4='\u000a'; (16进制)表示 \n
①byte,short,char->int->long->float->double(小容量自动转换换成大容量,容量为表数范围) ②多类型数据混合运算,将数据类型转换成最大的再进行运算 int a=10; long b=1000L; long c=a+b; ③byte,short,char运算时转换成int类型运算
①大容量放到小容量 ②使用强制转换符③boolean不能强制类型转换 ④byte,short,char之间做运算会先将自身提升成int类型 int b=1; int a=1; byte c=(byte)b + (byte)a; //编译不通过,byte类型运算时会自动转为int类型 正确写法:byte c = byte(b+a); 基本数据类型与String类型运算
变量部分练习
①计算机以二进制补码的形式保存所有的整数。 ②正数的原码、反码、补码都相同 ③负数的补码是其反码+1
① 取模结果的正负和被模数的正负有关 System.out.println( 4 % -3); // 1 System.out.println(-4 % 3); //-1 System.out.println(-4 % -3); //-1 ② 整数之间做除法只保留整数部分 ③ 计算机中运算顺序不同可能会导致不同结果 n2 = 10 / 4 * 4;//8.0 n2 = 10 * 4 / 4; //10.0
随意给出一个整数,打印显示它的个位数,十位数,百位数的值。格式如下: 数字xxx的情况如下: 个位数: 十位数: 百位数: |
Java Programming Fundamentals stage notes day02 Java basic grammar (on)
Guess you like
Origin blog.51cto.com/10421297/2423662
Recommended
Ranking