int num1 = 10; //常用 byte num2 = 127; short num3 = 30; long num4 = 40L; //Long类型要在数字后面加L
float num5 = 5.33f;//float类型要在数字后面加L double num6 = 3.141592653589793238462643;
char name = 'A'; //字符串,String不是关键字,类 String name2 = "中国欢迎你!";
boolean a = true; boolean b = false;
//整数拓展 二级制0b 十进制 八进制 0 十六进制0x int i= 10; int i2 = 010; //八进制0 int i3 = 0x10; //十六进制0x System.out.println("i" + i); //i=10 System.out.println("i2" + i2); //i2=8 System.out.println("i3" + i3); //i3=16
//float 有限 离散 接近但不等于 //double float a = 0.1f; //0.1 double b = 0.1; //0.1 System.out.println(a); //a=0.1 System.out.println(b); //b=0.1 System.out.println(a==b); //false
float a1 = 36265626526f; float a2 = a1 + 1; System.out.println(a1==a2); //true System.out.println(a1); //a1=3.6265628E10 System.out.println(a2); //a2=3.6265628E10
char s1 = 'A'; char s2 = '宋'; System.out.println("s1=" + s1); //S1=A System.out.println((int)s1); //数据类型转换之后65 System.out.println("s2=" +s2); //S2=宋 System.out.println((int)s2); //数据类型转换之后23435
//转义字符// \t 制表符// \n 换行 char c3 = '\u0061'; System.out.println("c3=" + c3); //c3=a System.out.println("Hello\tWorld"); //Hello World
萌新初学Java,如有哪些错误或不好的地方还请各位神仙大佬评论指出!