Java基础04 数据类型拓展与面试题讲解
数据拓展与面试题讲解
数据拓展
- 整数拓展
- 浮点数拓展
- 字符拓展
- 布尔值拓展
import static java.lang.System.*;
public class test04 {
public static void main(String[] args) {
//整数拓展
// 进制: 二进制 0b ; 八进制 0 ; 十进制 ; 十六进制 0x
int num1=0b10;
int num2=10;
int num3=010;
int num4=0x10;
for (int i : new int[]{num1, num2, num3, num4}) {
out.println(i);
}
out.println("================================"); //分割线
// 浮点数拓展
// float :有限,离散, 精度丢失(接近但不等于)
//银行业务 ,使用 BigDecimal 数学工具类 ,不同于 八大基本数据类型
//最好不要使用浮点数进行比较
float f1=123456790123456789l;
float f2=f1+1;
out.println(f1==f2); // 输出 true,此时居然 输出true!! 明显错误!!
float f=0.1f;
double d=1.0/10;
out.println(f==d); // 输出 false,此时居然 输出false!! 明显错误!!
out.println("================================"); //分割线
//字符拓展
// 1 .强制转换,用到 Unicode 编码表, 与 Asicii 编码表 的区别? 不初始化的话默认 u0000
char a1='a';
char a2='詹';
out.println(a1);
out.println(a2); //正常输出
out.println((int)a1);
out.println((int)a2); //转换后输出
//所有的字符本质还是数字, Unicode编码表,2字节,0~65535(现在不止了);Excel 2^16=65535:可表示 65536个字符
//U0000~UFFFF 16进制表示
char a3='\u0061'; //转译, Ox61对应 十进制 97,也就是小写a ; 此外注意 反斜杠u不能用在注释里面,不然会报错
out.println(a3);
// 2 .转义字符
out.println("hello\tworld"); // \t:空格
out.println("hello\nworld"); // \n:换行 ,这两个是最常用的
out.println("hello\'world"); // 还有很多
out.println("================================"); //分割线
//课外 ,现在只要知道,以后在探讨
String str1=new String("hello world");
String str2=new String("hello world");
out.println(str1==str2); //此时输出 false
out.println("----");
String str3="hello world";
String str4="hello world";
out.println(str3==str4); //此时输出 true
// 对象,从 内存角度 来分析这种情况
out.println("================================"); //分割线
//布尔值拓展
boolean flag=true;
if (flag==true){out.println("true");} //新手
if (flag){out.println("true");} //老手,默认是 true ,二者是等价的
// less is more! ; 代码要精简易读
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!