java基础入门
注释
标识符
八大基本数据类型
byte 8
short 16
int 32
long 64
float
double
char name ='中';
String name1 ="中国";
boolean fs = true;
boolean Fs = false;
拓展
public static void main(String[] args) {
int i = 10;
int i1 = 010;
int i2 =0x10;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
float f = 0.1f;
double d =1.0/10;
System.out.println(f==d);
System.out.println(f);
System.out.println(d);
float f1 = 31415926888888f;
float d2 = f1 + 1;
System.out.println(f1==d2);
System.out.println(f1);
System.out.println(d2);
char a1 = 'a';
char a2 = '额';
System.out.println(a1);
System.out.println(a2);
System.out.println((int)a1);
System.out.println((int)a2);
char c3 = '\u0061';
System.out.println(c3);
System.out.println("hello\tworld");
System.out.println("hello\nworld");
String sa = new String("hello,world");
String sb = new String("hello,world");
System.out.println(sa==sb);
String sc = "hello,world";
String sd = "hello,world";
System.out.println(sc==sd);
boolean flag = true;
if (flag==true){}
if (flag){}
}
强制转换和自由转换
public static void main(String[] args) {
int i = 128;
byte b = (byte)i;
double c = i;
System.out.println(i);
System.out.println(b);
System.out.println(c);
System.out.println((int)35.6);
System.out.println((int)-45.9f);
char d = 'a';
int f = d+1;
System.out.println(f);
System.out.println((char)f);
int money = 10_0000_0000;
int year = 20;
int total = money*year;
long total1 = money*year;
long total2= money*((long)year);
System.out.println(money);
System.out.println(total);
System.out.println(total1);
System.out.println(total2);
}