java中的数据类型和变量定义练习

This commit is contained in:
2025-12-23 14:33:27 +08:00
parent 61f1a6e9cd
commit 94a5e249bc
2 changed files with 51 additions and 2 deletions

View File

@@ -9,8 +9,8 @@ public class Demo01 {
//输出字符常量
System.out.println('A');
//输出布尔常量
System.out.println(true);
System.out.println(false);
//输出字符串常量
System.out.println("你好Java");
System.out.println("");
}
}

View File

@@ -0,0 +1,49 @@
package com.inmind;
//Java中基本数据类型的变量定义练习
/*
基本数据类型
四类八种基本数据类型:
数据类型 关键字 内存占用 取值范围
字节型 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 Demo02 {
public static void main(String[] args){
//定义字节型变量
byte b = 100;
System.out.println(b);
//定义短整型变量
short s = 1000;
System.out.println(s);
//定义整型变量
int i = 123456;
System.out.println(i);
//定义长整型变量
long l = 12345678900L;
System.out.println(l);
//定义单精度浮点型变量
float f = 5.5F;
System.out.println(f);
//定义双精度浮点型变量
double d = 8.5;
System.out.println(d);
//定义布尔型变量
boolean bool = false;
System.out.println(bool);
//定义字符型变量
char c = 'A';
System.out.println(c);
}
}