Fundamentals17 / 25
Up next

Fixed-width integers

class Main {
    public static void main(String[] args) {
        // int is 32-bit and silently wraps on overflow
        int max = Integer.MAX_VALUE;
        System.out.println(max + 1);
        // use long (64-bit) and the L suffix for large values
        long big = 1_000_000_000L * 1_000_000_000L;
        System.out.println(big);
    }
}
What you're solving

int wraps around; long holds more