0

This is just a short question but I'm still curious. When I initialize a int variable with the highest value 2147483647 it's allright. but when I want to initialize a long and assign it to it's max value, it gives me a "number too large" error

int i = 2147483647;
long j = 9223372036854775807;
Keheck
  • 131
  • 1
  • 10

1 Answers1

1

9223372036854775807 is an int literal, but is too large to fit into an int, hence the error. You can use a long literal instead by adding L to the end of it:

long j = 9223372036854775807L;
// Here --------------------^
Mureinik
  • 297,002
  • 52
  • 306
  • 350