sample1_3.java
来自「实现用于工程计算的的数学方法」· Java 代码 · 共 36 行
JAVA
36 行
/*
* 示例程序Sample1_3: 溢出
*/
package javaalgorithm.sample;
public class Sample1_3
{
public static void main(String[] args)
{
//
// 整数溢出
//
int maxInt = 2147483647;
int minInt = -2147483648;
int a = maxInt + 1;
int b = minInt - 1;
int c = maxInt * 2;
System.out.println("整数上溢:");
System.out.println("maxInt = " + maxInt);
System.out.println("maxInt + 1 = " + a);
System.out.println("maxInt * 2 = " + c);
System.out.println("整数下溢:");
System.out.println("minInt = " + minInt);
System.out.println("minInt - 1 = " + b);
//
// 浮点数溢出
//
float maxFloat = 3.4028235E38f;
float u = maxFloat * 2;
System.out.println("\n浮点数上溢:");
System.out.println("maxFloat = " + maxFloat);
System.out.println("maxFloat * 2 = " + u);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?