一、整数类型
| 数据类型 | 内存空间 | 取值范围 |
|---|---|---|
| byte | 8 | -128~127 |
| short | 16 | -32768~32767 |
| int | 32 | -2147483648~2147483647 |
| long | 64 | -9223372036854775808~9223372036854775807 |
package number;//定义包
public class Test {//定义类
public static void main(String[] args) {//主方法
int a=15;//定义int型变量
int b=30;
int c=a+b;
System.out.println(c);
}
}
2.byte型
package number;//定义包
public class Test2 {//定义类
public static void main(String[] args) {//主方法
byte a=19,b=-45;//定义byte型变量
byte c=(byte) (a+b);
System.out.println(c);
}
}
3.short型
package number;//定义包
public class Test3 {//定义类
public static void main(String[] args) {//主方法
short s = 20000/10;//定义short型变量
System.out.println(s);
}
}
4.long型
package number;//定义包
public class Test4 {//定义类
public static void main(String[] args) {//主方法
long n = 123456789L*987654321L;//定义long型变量
System.out.println(n);
}
}



