// Java 类型示例代码
public class JavaTypeExample {
// 基本数据类型
byte byteValue = 10; // 8位有符号整数
short shortValue = 100; // 16位有符号整数
int intValue = 1000; // 32位有符号整数
long longValue = 10000L; // 64位有符号整数
float floatValue = 2.71f; // 32位浮点数
double doubleValue = 3.141592653589793; // 64位浮点数
char charValue = 'A'; // 单个字符
boolean booleanValue = true; // 布尔值
// 引用数据类型
String stringValue = "Hello, World!"; // 字符串
Integer integerObject = 123; // 整数对象
Double doubleObject = 3.14; // 浮点数对象
public static void main(String[] args) {
JavaTypeExample example = new JavaTypeExample();
System.out.println("byte: " + example.byteValue);
System.out.println("short: " + example.shortValue);
System.out.println("int: " + example.intValue);
System.out.println("long: " + example.longValue);
System.out.println("float: " + example.floatValue);
System.out.println("double: " + example.doubleValue);
System.out.println("char: " + example.charValue);
System.out.println("boolean: " + example.booleanValue);
System.out.println("String: " + example.stringValue);
System.out.println("Integer Object: " + example.integerObject);
System.out.println("Double Object: " + example.doubleObject);
}
}
byte, short, int, long, float, double, char, 和 boolean。这些类型是直接存储在栈中的简单数据片段。Integer, Double 等)来将基本数据类型转换为对象,以便在需要对象的地方使用。这段代码展示了如何声明和初始化不同类型的变量,并通过 main 方法输出它们的值。
上一篇:java金额用什么数据类型
下一篇:java object转date
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站