Java UserInput
Java UserInput
The Scanner class is used to get user input, and it is found in the java.util package.
Method Description
nextBoolean
() Reads a boolean value from the user
Example:
import java.util.Scanner;
class Main {
// String input
// Numerical input
Task:
Identifiers
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
Literals
In Java, literals are the constant values that appear directly in the program. It can be assigned
directly to a variable. Java has various types of literals. The following figure represents a literal.
Java has a set of reserved words that have a special meaning to the compiler and cannot be used as
identifiers (such as variable names, class names, etc.). Here's a list of the reserved keywords in Java:
Widening casting is done automatically when passing a smaller size type to a larger size type.
int myInt = 9;
Narrowing casting must be done manually by placing the type in parentheses () in front of the value.
Realtime ex: