Files
javaSE-0113/day01/src/com/inmind/Demo03_Var.java
2026-01-13 16:45:01 +08:00

54 lines
2.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind;
/*
四类八种基本数据类型:
数据类型 关键字 内存占用 取值范围
字节型 byte 1个字节 -128~127
短整型 short 2个字节 -32768~32767
整型 int默认 4个字节 -231次方~2的31次方-1
长整型 long 8个字节 -2的63次方~2的63次方-1
单精度浮点数 float 4个字节 1.4013E-45~3.4028E+38
双精度浮点数 double默认 8个字节 4.9E-324~1.7977E+308
字符型 char 2个字节 0-65535
布尔类型 boolean 1个字节 truefalse
注意Java中的默认类型整数类型是int 、浮点类型是double 。
------------------------------------------------------------------
变量定义格式:
数据类型 变量名 = 数据值;
*/
public class Demo03_Var {
//定义java的每个基本数据类型的变量并打印输出(sout)
public static void main(String[] args){
//定义字节型变量 byte:1字节8个比特也就是8个0或者1取值范围:-128~127
byte b = -128;
b = 0;
System.out.println(b);
//定义短整型变量 short:2字节
short s = 1000;
System.out.println(s);
//定义整型变量
int i = 123456;
System.out.println(i);
//定义长整型变量
long l = 12345678900L;//注意java中如果要表示长整型long必须在后面加上L
System.out.println(l);
//定义单精度浮点型变量
float f = 5.5F;//注意java中如果要表示单精度的小数必须在后面加上F
System.out.println(f);
//定义双精度浮点型变量
double d = -0.1;//注意java中只要是小数默认就是double
System.out.println(d);
//定义布尔型变量
boolean bool = true;//在同一个范围内,变量名不能重复的
System.out.println(bool);
//定义字符型变量
char c = 'a';//字符:有且仅有一个内容
System.out.println(c);
//字符串在java中非常特殊它不是基本数据类型它是引用数据类型
String str = "所有的基本类型的变量定义完毕";
System.out.println(str);
}
}