package com.itheima._03基本数据类型;
/**
- @Description Demo031
- @Author songyu
@Date 2025-05-16 11:43
*/
public class Demo031 {public static void main(String[] args) {
//目标:基本数据类型的使用 //1.整型-字节 byte b1 = 127;//正确 //byte b2 = 128;//错误,范围 -128~127 //byte b3 = -129;//错误 //2.整型-短整型 short s1 = 32767; //short s2 = 32768;//错误,范围 -32768~32767 //short s3 = -32769;//错误 //3.整型-整型 int i1 = 2147483647; //int i2 = 2147483648; //错误,范围 -2147483648~2147483647 //4.整型-长整型,注意值的范围在整型内可以不用l或L,但是在长整型内必须使用l或L, // 推荐无论什么情况,long都写上L(可读性好) long l1 = 9223372036854775807L; //5.浮点型-单精度, 注意:浮点型数据后面添加f/F,推荐F // 注意:单精度浮点数精确只有7位(小数点前后加起来的位数),科学计算法精准9位数字 float f1 = 3.24111111111111111111111111111111111111111111111111111111111111111F; System.out.println(f1); float f2 = 123456789999F; System.out.println(f2);//1.2345678E7 //6.浮点型-双精度 ,注意:双精度浮点数后面D或d可有可无,推荐加上D,默认小数是double // 科学计算法精确位数17位(数点前后加起来的位数) double d1 = 1234567890123456789123456789D; System.out.println(d1); // 扩展:如果希望小数精准,后面会学习BigDecimal //7.字符型 char c1 = 'a'; System.out.println(c1); System.out.println((int)c1);//97 //8.布尔型 boolean bl1 = true; //起变量名字的注意事项 // 1.不能以关键字作为变量名、方法名或类名 //long long = 100; 报错 //String String ="abc"; 可以,String不是关键字 // 2.不能以数字开头,并且包含特殊字符&,%,#,;等 //String 123a = "abc"; 报错 //String a123; = "abc"; 报错 // 3.变量名、方法名建议小驼峰命名,类名建议大驼峰命名,包名要求全部小写}
}