LEARN MATE Request book Contact us quizes Books Home
Variables
Variables are containers for storing data values. In Java, there are different types of variables, for example: String - stores text, such as "Hello". String values are surrounded by double quotes int - stores integers (whole numbers), without decimals, such as 123 or -123 float - stores floating point numbers, with decimals, such as 19.99 or -19.99 char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes boolean - stores values with two states: true or false

To create a variable, you must specify the type and assign it a value: int myNum; myNum = 15; System.out.println(myNum);;// Now myNum is 10Note: If you assign a new value to an existing variable, it will overwrite the previous value:

Note that if you assign a new value to an existing variable, it will overwrite the previous value: printf("Hello World!"); In many other programming languages (like Python, Java, and C++), you would normally use a print function to display the value of a variable. However, this is not possible in C:

int myNum = 15; printf(myNum); // Nothing happens