2022-7-17至18--java基础
1.注释、标识符、关键字
注释
- 书写注释是一个很好的习惯
- 注释不会被执行,是给我们写代码的人看的,理清路线
//单行注释
/*
多行注释
*/
/** 文档注释 / --能被识别,放一些注解,作者,时间信息等等
例如:
/*
*@Description HelloWorld
*@Author shuxin
*/
标识符、关键字

标识符注意事项

2.数据类型
- ①byte--字节
占一个字节,范围:-127至127 - ②short--短整型
占两个字节,范围:-32768至32767 - ③int--整型
占四个字节,范围:-2147483648至2147483647 - ④long--长整型
占八个字节,范围:-9223372036854775808至9223372036854775807 - ⑤float--单精度型
占四个字节 - ⑥double--双精度型
占八个字节 - ⑦char--字符型
占两个字节 - ⑧boolean--布尔值
结果只有true和false,非真即假,非假即真
public class demo2 {
//整数拓展 进制(2(0b开头).8(0开头).16(0x开头).10)
public static void main(String[] args) {
int i = 10;
int o = 010;
int p = 0x10;
System.out.println(i);
System.out.println(o);
System.out.println(p);
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);
System.out.println("---------------------------");
float d1 = 655555f;
float d2 = d1 + 1;
float d3 = d2 + 2;//超过范围进行计算,值就不改变,比较的时候时相等的
System.out.println(d1 == d2);
System.out.println(d2 == d3);
System.out.println(d1);
System.out.println(d2);
System.out.println(d3);
// 最好完全避免用浮点数进行比较;
// 不用浮点数;
// 浮点数精度不够;
char c1 = 'A';
char c2 = '中';
char c3 = '\u0079';
System.out.println(c1);
System.out.println((int) c1); //强制转换
System.out.println(c2);
System.out.println((int) c2);
//所有的字符本质还是数字,强制转换成
//ASCII表
System.out.println(c3);
}
}
布尔值扩展
boolean flag = true;
if (flag == true){}
if (flag){}
//两种写法一模一样,小括号里不为零则全为真
面试题扩展
System.out.println("hello\nworld");
// 转义字符
// \n换行
// \t制表符
String sa = new String("hello world");
String sc = new String("hello world");
System.out.println(sa.equals(sc));
String ss = "hello world";
String sv = "hello world";
System.out.println(ss==sv);
// equals比较的时内容,==比较的是内存地址
浙公网安备 33010602011771号