八大基本数据类型的扩展
//八大基本数据类型
public class Demo03 {
public static void main(String[] args) {
//八大基本数据类型
//整数
int num1 = 100;//最常用
byte num2 = 20;
short num3 = 30;
long num4 = 30L; //Long类型要在数字后面加个F
//小数:浮数点
float num5 = 50.1F; //Lfloat类型要在数字后面加个F
double num6 = 3.14500725;
//字符
char name = '国';
//字符串,String不是关键字,是类
//String namea = "杨志康";
//布尔值:是非
boolean flag = true;
//boolean flag = false;
}
}
public class Demo02 {
public static void main(String[] args) {
String a="hello";
int num = 10;
System.out.println(a);
System.out.println(num);
}
数据类型
强类型语言
-
要求变量的使用要严格符合规定,所有变量必须先定义后才能使用
弱类型语言
-
Java的数据类型分为两大类
-
基本类型
-
数值类型:
-
整数类型:
-
1.byte占一个字节范围:-128-127
-
2.short占两个字节范围:-32768-32767
-
3.int占四个字节范围:-2147483648-2147483647
-
4.long占八个字节范围:-92 -999很长
-
浮点类型
-
1.float占四个字节
-
1.double占八个字节
-
字符类型:char占2个字节
2.boolean类型:占一位其值只有true和false两个(是非对错)
引用类型
-
引用数据类型:
-
类
-
接口
-
数组
什么是字节
-
位(bit):是计算机 内部数据 储存的最小单位,11001100是一个八位二进制数。
-
字节(byte):是计算机中数据处理的基本单位,习惯上用大写 B 来表示,
-
1 B (byte,字节) = 8bit(位)
-
字符:是指计算机中使用的字母、数字、字和符号
-
1bit表示1位,
-
1Byte表示一个字节 1B=8b。
-
1024B=1KB
-
1024KB=1M
-
1024M=1G.
public class Demo04 {
public static void main(String[] args) {
//整数拓展: 进制 二进制(0b) 十进制 八进制(0) 十六进制(0x)
int i = 10;
int i2 = 010; //八进制0
int i3 = 0x10; //十六进制0x 0~9 A~F 16
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
System.out.println("=============================================");
//==============================================================
//浮点数扩展 银行业务怎么表示 钱
//============================================================
//float
//double
float f = 0.1f; //0.1
double d = 1.0/10; //0.1
System.out.println(f==d);//false
}
}
基本语句的扩展
package K;
public class ccc {
public static void main(String[] args) {
//float
//double
float f = 0.1f; //0.1
double d =1.0/10; //0/1
System.out.println("=============================================");
System.out.println(f==d);
System.out.println(f);
System.out.println(d);
System.out.println("杨志康好帅 ");
float d1=234567;
float d2=d1+1;
System.out.println(d1==d2);//true
System.out.println("=====================================");
char c1 = 'a';
char c2 ='中';
System.out.println(c1);
System.out.println((int)c1);//强制换行
System.out.println(c2);
System.out.println((int)c2);//强制换行
//所有的字符本质还是数字
//编码 Unicode 表:(97 = a 65=A)2字节 0 - 65536 Excel 2 16 = 65536
// U0000 UFFFF
char c3 = '\u0061';
System.out.println(c3);//a
//转义字符
//\t 制表符
// \n 换行
//....
System.out.println("Hello\nWorld");
//
System.out.println("======================================");
String sa = new String(origina|:"hello world");
String sb = new String(origina|:"hello world");
System.out.println(sa==sb);
String sc ="hello world";(重点)
String sd ="hello world";
System.out.println(sc==sd);
//对象 从内存分析
//布尔值扩展
boolean flag = true;
if (flag==true){} //新手
if (flag){} //老手
//Less is More! 代码要精简易读
}
}