数据类型扩展及面试题

package java基础;

import java.awt.PageAttributes.OriginType;

public class Data {public static void main(String[] args) {
//整数拓展 进制 二进制0b 八进制0 十进制 十六进制0x
int i = 0b10;
int i2= 010;
int i3= 10;
int i4 = 0x10;
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println(i4);
System.out.println("====================");

 

 


//===============================================
//面试题:银行业务如何表示 钱? bigdecimal 数学工具类
//================================================
//浮点数拓展 特性 :有限 离散 舍入误差 接近但不等于
//最好完全避免使用浮点类型进行比较
//最好完全避免使用浮点类型进行比较
//最好完全避免使用浮点类型进行比较
//如果需要进行计算并且不能让它有误差,就用java定义好的一个类,叫"bigdecimal"
float f=0.1f;
double d=0.1;
System.out.println(f);
System.out.println(d);
System.out.println(d==f);

 

 


//===================================================
//字符拓展
//===================================================
System.out.println("====================");
char a1 = 'a';
char a2 = '中';
char a3 = 'A';
System.out.println(a1);
System.out.println((int)a1);//强制转换
System.out.println(a2);
System.out.println((int)a2);//强制转换
System.out.println((int)a3);
//所以的字符本质还是数字,因为在电脑里只能储存数字,字符是通过unicode编码转化出来的。
//编码 unicode (a=97 A=65)占2字节 范围是2的16次方
//char a4='/u0061';; System.out.println(a4);本该输出a 因为Unicode中/u0061=a,
//但报错说--Invalid character constant(无效字符常量)问题待定

 

 

//===================================================
//转义字符
//===================================================
// \n 换行本义是光标往下一行(不一定到下一行行首)。n 的英文newline,控制字符可以写成LF,即Line Feed
// \t 制表符
// \b 退格
// \r 回车 回车 \r 本义是光标重新回到本行开头。r 的英文return,控制字符可以写成CR,即Carriage Return
// \f 换页
// \\ 反斜杠
// \'
// \"
System.out.println("====================");
System.out.println("hello\nworil");
System.out.println("hello\tworil");
System.out.println("hello\bworil");
System.out.println("hello\rworil");
System.out.println("hello\fworil");
System.out.println("hello\\woril");
System.out.println("hello\'woril");

//===================================================
//对象 从内存分析
//===================================================
System.out.println("====================");
String aa="hello,woril";
String ab = "hello,woril";
System.out.println(aa==ab);//true
String ac = new String("hellom=,woril");
String ad = new String("hellom=,woril");
System.out.println(ac==ad);//false
//都是地址,第二个是不同的两个空间,第二个是同一个空间,因为字符串是常量。

 


//==================================================

//布尔扩展
//===================================================、
boolean flag =true;
if (true) {//if(如果)如果它是true就执行{}里的代码,否则执行else{}里面的代码;



}else {
//代码要精简易读
}
}

}

posted @ 2022-04-10 13:56  教诲  阅读(36)  评论(0)    收藏  举报