public class TestClass {
public static void main(String[] args) {
int x = 1____3; //1
long y = 1_3; //2
float z = 3.234_567f; //3
System.out.println(x+" "+y+" "+z);
}
}
I understood that you should always put L or l when creating a long from a literal because by default the numerical literals (without decimal) are int.
When is necessary put L or l in literals to create long vars?
You need to put L or l when the value of the literal that you want to write is too big to fit into an int. If you don't append L or l then the compiler will take it as an int and since the value is too big, it will complain that it is too big for an int.
FYI, you don't need to worry about the actual value after which you have to put an L to make it compile for the exam.
If you like our products and services, please help us by posting your review here.
admin wrote:You need to put L or l when the value of the literal that you want to write is too big to fit into an int. If you don't append L or l then the compiler will take it as an int and since the value is too big, it will complain that it is too big for an int.
FYI, you don't need to worry about the actual value after which you have to put an L to make it compile for the exam.