It's because when you use the scientific notation you create a floating point number (a double in your example). And you can't assign a floating point to an integer (that would be a narrowing primitive conversion, which is not a valid assignment conversion).
So this would not work either for example:
int y = 2d; //can't convert double to int
You have a few options:
- explicitly cast the floating point to an integer:
int y = (int) 2e6;
- with Java 7+ use a thousand separator:
int y = 2_000_000;