Hi I'm having trouble understanding why this isn't working
if(Long.parseLong(morse) == 4545454545){
System.out.println("2");
}
Where morse is just a String of numbers. The problem is it says Integer number too large: 4545454545, but I'm sure a Long can be much longer than that.
You need to use 4545454545l
or 4545454545L
to qualify it as long
. Be default , 4545454545
is an int
literal and 4545454545
is out of range of int
.
It is recommended to use uppercase alphabet L
to avoid confusion , as l
and 1
looks pretty similar
You can do :
if(Long.valueOf(4545454545l).equals(Long.parseLong(morse)) ){
System.out.println("2");
}
OR
if(Long.parseLong(morse) == 4545454545l){
System.out.println("2");
}
As per JLS 3.10.1:
An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With