Files
javaSE-260914/day01/src/com/inmind/Demo02.java
T

65 lines
2.3 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 {//定义一个类,类是有范围
//psvm:主方法的快捷方式
public static void main(String[] args) {//程序主入口
//变量定义的格式:数据类型 变量名 = 数据值;
//定义java中4类8种基本数据类型
//定义字节型的变量(-128~127)
byte b = -128;
//定义短整型的变量
short s = 12800;
//定义int类型的变量
int i = 2000000000;
System.out.println(i);
//定义long类型的变量(注意:java中只要是整数默认是int类型,如果要表示长整型,必须在后面加l或L)
long l = 20000000000L;
System.out.println(l);
//定义float类型的变量(注意:java中只要是小数默认是double类型,如果要表示单精度型,必须在后面加f或F)
float f = 1.1F;
System.out.println(f);
//定义double类型的变量
double d = 1.1;
System.out.println(d);
//定义char类型的变量
char c = '中';
System.out.println(c);
//定义boolean类型的变量
boolean b2 = false;
System.out.println(b2);
//扩展,定义字符串类型的变量
String str = "abc";
System.out.println(str);
//一个变量定义好后,是可以修改
str = "这是修改后的值";
System.out.println(str);
//在java中同一个范围内,变量名不能重复,{}就是范围
int i1 = 100;
}
}