Skip to content

Commit be360f0

Browse files
committed
feat: Add Literal1 class demonstrating long literal with suffix
WHAT the code does: - Defines a `Literal1` class with a `main()` method. - Declares a `long` variable `L` with value `999999999999L`. - Prints the value to the console. WHY this matters: - Demonstrates how to define **long literals** in Java. - By default, numeric literals are treated as `int`. → The suffix `L` (or `l`) tells the compiler to treat it as a `long`. - Important when dealing with values larger than the `int` range (±2,147,483,647). HOW it works: 1. `999999999999` exceeds `int` range. 2. Adding `L` ensures the literal is compiled as a `long`. 3. Program prints `999999999999`. Tips & gotchas: - Always use uppercase `L` instead of lowercase `l` to avoid confusion with `1`. - If the literal fits within `int` range, suffix `L` is optional. - For very large numbers, consider `BigInteger`. Use-cases: - Handling large numbers in financial or scientific calculations. - Educational demo for **numeric literal suffixes** in Java. - Ensures clarity when working with values beyond `int`. Short key: class-literal1-long-literal. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent eb6b369 commit be360f0

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Section10Methods/PracticeProblems/src/Literal1.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
public class Literal1 {
2-
public static void main(String args[])
3-
{
2+
public static void main(String args[]) {
43
long L = 999999999999L;
54
System.out.println(L);
65
}

0 commit comments

Comments
 (0)