0
0

More than 1 year has passed since last update.

intのmax値を超えるとどうなる

Posted at
    public static void main(String[] args) {
        int i1 = Integer.MAX_VALUE;
        System.out.println(i1);
        System.out.println(i1+1);
        System.out.println(i1+2);
        System.out.println("----------------------");
        byte b1 = Byte.MAX_VALUE;
        System.out.println(b1);
        System.out.println(b1+1);
        System.out.println(b1+2);
        System.out.println(b1+2147483647-Byte.MAX_VALUE);
        System.out.println(b1+2147483647-Byte.MAX_VALUE+1);
    }

max値を超えるとmin値になる
byteは計算すると、intのmax値となる

2147483647
-2147483648
-2147483647
----------------------
127
128
129
2147483647
-2147483648
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0