-
关键字
abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instance of int interface long native new package private protected public retum strictfp short static super switch synchronized this throw throws transient try void volatile while
标识符注意点
-
-
首字母之后可以是任意组合
-
不能关键字作为方法名或者变量名
-
标识符是大小写敏感的
基本数据类型
整型==》byte字节型
short短整型
int整型
long长整型
float 单精度浮点型
double 双精度浮点型
char 字符型
boolean布尔型
public class HelloWord{
public static void main(String[] args){
byte i = 10; // 整数拓展 1字节 8位
int i1 = 10; // 4字节 32位
short i2 = 10; // 2字节 16位
long i3 = 10L; //long型需在变量后加L以便识别 8字节 64位
float a = 1.0f; //浮点型 单精度浮点型在变量后加F
double a1 = 3.1415926;
char b = ‘中’; //char类型 一个字符
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
System.out.println(==========================================================================);
//===================================================================================
//浮点数拓展 银行业务怎么表示?钱
//BigDecimal 数学工具类
//========================================================================================
//float 有限 离散 舍入误差 大约 接近但不等于
//double
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
float f = 0.1f; //输出为0.1
double d = 1.0/10; //输出为0.1
System.out.println(f==d); //flase
float j = 121212121f;
float k = j+1;
System.out.println(j==k); //true
//===================================================================================
//字符拓展
//========================================================================================
char c1 = 'a';
char c2 = '中';
System.out.println(c1); //输出a
System.out.println(c2); //输出中
System.out.println((int)c1); //强制转换,输出
System.out.println((int)c2); //强制转换int类型
//所有字符的本质是数字
//===================================================================================
//===================================================================================
String name = new name("王子");
String name1 = new name("王子");
System.out.println(name==name1); //flase
System.out.println(name equse name1); //true
//布尔型拓展
boolean flag = true;
if(flag==true){}; //上下意思相同
if(flag){};
//less is more 代码要精简易读
}
}
浙公网安备 33010602011771号