DAY2021.10.06 数据类型
| 类型 | 字节数 |
| byte | 1 |
| short 短整型 | 2 |
| int | 4 |
| long 长整型 | 8 |
| float | 4 |
| double | 8 |
| boolean | 1 |
| char | 2 |
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
System.out.println("giao");
int a=10;
int b=010;//八进制在数字前加0
int c=0x10;//十六进制在数字前加0x
System.out.println(a);
System.out.println(b);
System.out.println(c);
long d=10789456132L;//L必须加,因为字面值都是以int类型存储。
System.out.println(d);
}
}
大容量转小容量需要强制转换符,可能会损失精度。
long d=10L; System.out.println(d); int a1=(int) d;//强制转换 System.out.println(a1);
计算机存储数据存储的是补码。
强行转了之后,丢失前四位,long 8位,int 4位。
byte b=50;//可以编译通过 byte b=127;//编译通过 byte b=128;//编译不能通过
但是,在实际编译的时候,以上代码编译通过了,这说明:在java语言当中,当一个整数型字面值没有超出byte类型取值范围的话,该字面值可以直接赋值给byte类型的变量。



