Files
javaSE251223/day01/src/com/inmind/Demo02.java

58 lines
1.8 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;
//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){
//定义字节型变量1个字节
byte b = -128;
b = 100;
System.out.println(b);
//定义短整型变量2个字节
short s = -32768;
System.out.println(s);
//定义整型变量
int i = 123456;
System.out.println(i);
//定义长整型变量(8字节)
long l = 12345678900L;
System.out.println(l);
//定义单精度浮点型变量
float f = 5.5F;
System.out.println(f);
//定义双精度浮点型变量
double d = -8.5;
System.out.println(d);
//定义布尔型变量
//ctrl+D:复制一行
boolean bool = false;
boolean bool1 = true;
System.out.println(bool);
//定义字符型变量
char c = ' ';
System.out.println(c);
//注意事项:变量可以先定义后赋值的,但是使用之前必须赋值
//定义一个num的int型变量不赋值
int num;
num = 200;
System.out.println(num);
}
}