java数据类型常见的类型(面试笔试容易考)
各个类型的简单使用
package base;
public class Demo1 {
public static void main(String[] args) {
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);
System.out.println(d);
System.out.println(f==d);
System.out.println("****************************");
float d1 = 12312312123f;
float d2 = d1 + 1;
float d3 = 123f;
float d4 = d3 + 1 ;
System.out.println(d1 == d2 );
System.out.println(d3 == d4 );
System.out.println("****************************");
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
System.out.println(c2);
System.out.println((int)c1);
System.out.println((int)c2);
System.out.println("****************************");
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){}
}
}
类型转换问题
package base;
public class demo2 {
public static void main(String[] args) {
int i = 128;
byte b = (byte)i;
System.out.println(i);
System.out.println(b);
double d = i;
System.out.println(d);
System.out.println("********************");
System.out.println((int)23.7);
System.out.println((int)-45.86f);
System.out.println("********************");
int money = 10_0000_0000;
int years = 20;
int total = money*years;
System.out.println(total);
long total2 = money*years;
System.out.println(total2);
long total3 = money*(long)years;
System.out.println(total3);
}
}