Data Types

Data Types

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.

Reading And Printing Data

  • 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;.

Variables

The variables are used to store data of certain type.

Their value can be changed any time.

Example of variables definitions:

Basic program example:

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.