Literals
Literals are fixed values that we can use directly in our programs.For example, 5, -12.5, 'c' etc.
Different types of literals are mentioned below.
Literals are fixed values that we can use directly in our programs.For example, 5, -12.5, 'c' etc.
Different types of literals are mentioned below.
Numeric value without any decimal part.For example, 4,-6,0,345,etc.
Numeric values that have decimal parts. For example, 3, -4.32, 8.0 etc.
Single character enclosed inside single quotes. For example, ‘a’ ‘u’ ‘+’ etc.
In programming, variables are used to store data so that we can use them later in the program.
Next, we will learn to create variables.
There are two things needed to create a variable:
● Variable name – a unique name to indicate the variable
● Data Type – the type of data variable can store
For example,
int age;
Here, we have created a variable named age. This variable can only store integer values. We know this because we have
used int to declare the variable.
Note: The ;(semicolon) at the end is mandatory. It indicates the end of the statement.
To create variables that can store decimal numbers, we can use double.
For example,
double salary;
Here, salary is a variable that can only store floating-point numbers (decimal numbers).
● Run the following program in your compiler to get the feel of how variables are used in a Java program.
● copy the below code and paste it your java compiler.