Skip to main content

Variables

Java | Variables: Variables are using to store the data.

Details of Variables:

    Variable Declaration and Initialization: Create the variable and assign the value to it.
                            Ex: int i = 1.
    Modification of Variables: Variables can modify by doing operators on them.
                             Ex: i = i + 2.
    Types of Variables: Variable types are integer, string, float/double and boolean.
                              Ex: 1 is integer, "Java" text with double quotes is string, 1.43 number with decimal values are float/double and true/false is boolean. 

Here is the Code:

  1. import java.io.*;

  2. class Main {
  3. public static void main (String[] args) {
  4.     // Declaration and Assigning
  5.     int i = 1;
  6.     System.out.println(i);
  7.     // Modification
  8.     i = i + 2;
  9.     System.out.println(i);
  10.     // Types
  11.     double j = 1.43;
  12.     System.out.println(j);
  13.     String s = "Java";
  14.     System.out.println(s);
  15.     boolean b = true;
  16.     System.out.println(b);
  17. }
  18. }

Output:
1
3
1.43
Java
true

Here is the Video: