Java Math incrementExact() 方法
示例
遞增不同的數字
System.out.println(Math.incrementExact(12002));
System.out.println(Math.incrementExact(18));
System.out.println(Math.incrementExact(32));
System.out.println(Math.incrementExact(947));
自己動手試一試 »
定義和用法
incrementExact()
方法返回比指定整數大 1 的值,如果發生溢位則丟擲異常。這可以防止因溢位而導致的不正確結果。
語法
以下之一
public static int incrementExact(int x)
public static long incrementExact(long x)
引數值
引數 | 描述 |
---|---|
x | 必需。要遞增的整數。 |
技術詳情
返回 | 一個 int 或 long 值,表示比整數大 1 的值。 |
---|---|
丟擲 | ArithmeticException - 如果遞增導致溢位。 |
Java 版本 | 1.8+ |
❮ Math 方法