// 将 int 类型转换为 long 类型的示例代码
public class IntToLongExample {
public static void main(String[] args) {
// 定义一个 int 类型的变量
int intValue = 123;
// 将 int 类型的变量转换为 long 类型
long longValue = (long) intValue;
// 输出转换后的结果
System.out.println("int 值: " + intValue);
System.out.println("转换后的 long 值: " + longValue);
}
}
int 是 32 位整数类型,而 long 是 64 位整数类型。由于 long 的范围更大,因此将 int 转换为 long 是安全的。(long) 将 int 类型的变量 intValue 转换为 long 类型的变量 longValue。上一篇:java面向对象的三大特性
下一篇:java构造函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站