JAVA_SE 基础知识Review
基本数据类型
、
public class dataTypes {
public static void main(String[] args) {
byte num1 = 1;
short num2 = 1;
int num3 = 1;
long num4 = 1L;
float num5 = 1F;
double num6 = 1.0;
char num7 = '蒋';
boolean flag = true;
boolean flag2 = false;
test1();
}
static void test1(){
int i = 10;
int i2 = 010;
int i3 = 0x10;
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println("===========================");
float f = 0.1f;
double d = 1.0/10;
System.out.println(f==d);
System.out.println(f);
System.out.println(d);
float d1 = 12423423423546f;
float d2 = d1 + 1;
System.out.println(d1==d2);
System.out.println("===========================");
char c1 = '中';
System.out.println(c1);
System.out.println((int)c1);
char c2 = '\u0061';
System.out.println(c2);
System.out.println("===========================");
System.out.println("Hello\tWorld!");
boolean flag = true;
if(flag == true){}
if(flag){}
}
}
数据类型之间的转换
public class dataTypeToType {
public static void main(String[] args) {
int i = 128;
byte b = (byte)i;
System.out.println(i);
System.out.println(b);
System.out.println("=============================================");
System.out.println((int)234.343);
System.out.println((int)-234.343f);
System.out.println("=============================================");
char c = 'a';
int d = c+1;
System.out.println(d);
System.out.println((char)d);
System.out.println("=============================================");
int money = 10_0000_0000;
int year = 20;
int total = money * year;
long total2 = money * year;
long total3 = (long)money * year;
System.out.println(total);
System.out.println(total2);
System.out.println(total3);
}
}