Data types define what information is stored
The most used of them are:
int | Whole number. |
---|---|
double | Floating point number. |
String | Sequence of characters (text). |
char | Represents a single symbol. |
boolean | Can have only 2 values - true or false . |
Scanner scanner = new Scanner(System.in);
followed by scanner.nextLine();
- reading data.System.out.println();
- printing data.In order to use Scanner
the following line needs to be added
import java.util.Scanner;
.
The variables are used to store data of certain type.
Their value can be changed any time.
Example of variables definitions:
Write a program that prints "Starting the program." Afterwards it must read a word and print it back.
Solution:
Input:
Output:
Explanation:
import java.util.Scanner;
is added so Scanner
can be used.System.out.println
is used to print message to the user.