How does the law of inertia work?
1. next() Function: Reads the next token (word) from input. Delimiter: Stops reading when it encounters whitespace (space, tab, or newline). Ignores: Leading whitespace before the token. Use case: Good for reading single words. Example: Scanner sc = new Scanner(System.in); System.out.print("Enter yoRead more
1. next()
Function: Reads the next token (word) from input.
Delimiter: Stops reading when it encounters whitespace (space, tab, or newline).
Ignores: Leading whitespace before the token.
Use case: Good for reading single words.
Example:
Input:
Output:
👉 It only captures "Rahul" because next() stops at the first space.
2. nextLine()
Function: Reads the entire line of input (until Enter/
\n).Delimiter: Stops only when the newline character is encountered.
Use case: Good for reading sentences or full lines with spaces.
Example:
Input:
Output:
👉 Here it captures the whole line, including spaces.
⚡ Key Differences Table
| Feature | next() | nextLine() |
|---|---|---|
| Reads up to | Whitespace (space, tab, newline) | End of line (\n) |
| Can read spaces? | ❌ No (stops at space) | ✅ Yes (includes spaces) |
| Best for | Single words/tokens | Full sentences / whole line |


The law of inertia, also known as Newton's First Law of Motion, states that an object will remain at rest or move in a straight line at a constant speed unless acted upon by an external force. This law highlights the concept that objects tend to maintain their current state of motion. Key Points ofRead more
The law of inertia, also known as Newton’s First Law of Motion, states that an object will remain at rest or move in a straight line at a constant speed unless acted upon by an external force. This law highlights the concept that objects tend to maintain their current state of motion.
Key Points of the Law of Inertia
The law of inertia explains why no force is needed to keep an object moving at a constant velocity and why forces are required to change the motion of objects.
See less