一、Java数据类型:int byte short long char 浮点类型:float double 布尔类型:boolean
二、运算符:算数运算符,关系运算符,赋值运算符,逻辑运算符
三、数据类型转换:自动转换,强制转换
代码如下:
public class yl{
public static void main(String[] args){
System.out.println(“2020080605019”);
int num1;
num1=5;
System.out.println(num1);
double num2=3.14;
System.out.println(num2);
byte num3=(byte)200; //强制转换数据丢失
System.out.println(num3);
{ //局部作用域{ }
int num4=500;
System.out.println(num4);
}
byte num4=127;
System.out.println(num4);
short num5=50;
System.out.println(num5);
long num6=100000000111L;//注意:long后需要添加L
System.out.println(num6);
double num7=3.14;
System.out.println(num7);
float num8=3.14F; //注意:float后需要添加F
System.out.println(num8);
char var1=‘A’;
System.out.println(var1+0) ; //ascall码转换
System.out.println(var1+1);
char var2=‘国’;
System.out.println(var2);
boolean var3=true;
System.out.println(var3);
boolean var4=var3;
System.out.println(var4);
boolean var5=false;
System.out.println(var5);
int a,b,c;
a=100;
b=200;
c=300;
System.out.println(a);
System.out.println(b);
System.out.println©;
System.out.println(1024);
System.out.println(3.14);
int num9=(int)100L; //强制转换结果为100
System.out.println(num9);
int num10=(int)6000000L;
System.out.println(num10);
int num11=(int)3.14; //强制转换
System.out.println(num11);
var1=‘B’;
System.out.println(var1+0);
var1=‘Z’;
System.out.println(var1+0);
var1 =‘0’;
System.out.println(var1+0);
System.out.println(0);
var1=‘国’;
System.out.println(var1);
System.out.println(var1+0);
byte num12=10;
byte num13=20;
int result1=(byte)(num12+num13);
System.out.println(result1);
System.out.println(30+20);
int e=20;
int d=30;
System.out.println(e+d);
System.out.println(e-d);
System.out.println(e*10);
int x=10;
int y=3;
System.out.println(x/y);
double result2=x/y;
System.out.println(result2); // double类型结果为3.0
int result3=x%y;
System.out.println(result3);
double z=3;
double result4=x+z;
System.out.println(result4); //结果:13.0
}
}
运行结果:
心得:特别注意强制转换。