常量
数据类型
| 数据类型 | 位数 | 范围 | notice | notice |
|---|---|---|---|---|
| byte | 8 | -2^7 ~ 2^7-1 | 整数在计算机中的存储 | |
| short | 16 | |||
| int | 32 | 1 | ||
| long | 64 | 1 l or 1 L | ||
| 0123:表示八进制123 | ||||
| 0x123:表示十六进制123 | ||||
| float | 32 | 1.1f | 浮点数在计算机中的存储 | |
| double | 64 | 1.1 or 1.1d | 近似存储,因此不能比较两个浮点数 | |
| char | ||||
| bool | true和false不对应任何整数值 |
运算
除法
没有++,—
op1+=op2等价于op1=(T)(op1+op2)
int sum=0;
sum+=4.5; //sum==4
sum+=4.5; //sum=(int)(sum+4.5)
变量
命名
byte —>short,char—>int—>long—>float—>double
8 16 16 32 64 32 64
char ch = 'B';cout << ch + 3 << endl; //69char ch = 66;cout << ch << endl; //C
public class E_char{public static void main(String args[]){char ch1='B';char ch2=67;System.out.println(ch1+3); //69System.out.println(ch2); //C}}
- 精度问题

流程控制
for ( elemType i in array ):此时i不是下标,而是数组的每一个元素
public class ForTest{public static void main(String args[]){int array[]={10,20,30,40,50};for(int i:array){System.out.println(i);}}}
