W
W
WannaCreative2016-08-09 23:05:28
Java
WannaCreative, 2016-08-09 23:05:28

Why is it showing as an error?

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        long l = 2147483648;
        int r = (int) l;
        System.out.println(r);
    }
}

After all, long = - 9*1018 .. 9*1018

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanan Yuzb, 2016-08-09
@WannaCreative

Потому, что по-умолчанию этот литерал воспринимается как int. Поэтому надо писать так

long l = 2147483648L;
int r = (int) l;
System.out.println(r);

И все будет ОК.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question