关于Java 八大基本数据类型
1、6个数字类型:整型4个,小数类型2个
byte a= 1;//字节型(一个字节)
short b= 2;//短整型(两个字节)
int c = 3 ;//整型(四个字节)
long d = 4 ;//长整型(八个字节)
** 以上为整型**
float e=0.5f; //单精度小数类型(四个字节)float赋值时后面必须加f或F
double f = 0.6 ;//双精度(八个字节)double赋值后面可加d或D或不加
2、布尔类型:boolean
boolean g=true; //布尔类型(1个字节),只有两个值即为true或false
3、字符型:char
char h = ' ';//字符型(两个字节)
4、系统常用类型
字符串(string)<---- 不属于八大系统类型
String str = "啦啦啦";
七.隐式转换和强制转换(该处以程序说明)
public class Test1 {
//一个文件中可以写很多类,但只有一个类public
public static void main(String[] args) {
// TODO Auto-generated method stub
//声明变量:声明+初始化值
int a;
a=1;
double b =3.5;
char c = 'A';
double sum =a+b+c;
//隐式转换(byte-->short,char-->int-->long-->float-->double)转换等级由低到高
//强制类型转换(由高到低)八大基本数字类型除了Boolean都可实现
long l =2113;
int i =(int)l;<-----强制转换(由高到低转换)
char x='Z';
int y = x;<-----隐式转换(由低到高直接转换)
System.out.println(y);
int s1 =97;
char s2 =(char)s1;
System.out.println(s2);
double x1 =3.14;
int x2 = (int)x1;
System.out.println(x2);
}
}
转载:https://blog.csdn.net/weixin_44145265/article/details/102483367
查看评论