P
P
progforgood2016-12-01 04:10:01
Java
progforgood, 2016-12-01 04:10:01

Why put the letter L after the number?

class temp {    
  public static void main(String args[]) {    
    long L; 
    double D; 
   
    L = 100123285L;  //что означает буква "L" в 100123285L? Ведь результат выполнения не меняется
    D = L; 
   
    System.out.println("L and D: " + L + " " + D); 
   
  }    
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2016-12-01
@progforgood

Come up with a number that goes beyond intand try to assign it to a variable longwithout "L", the program will not compile.

V
Vasily Melnikov, 2016-12-01
@BacCM

In this example, it is not necessary, the compiler itself will be able to choose the type of the constant, and most likely there will be a maximum warning.
But there are situations when, for example, a constant is involved in calculations, again, a smart compiler most often "guesses" what the programmer wants.
Or if the constant is a function parameter that can take different types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question