variables are containers used for storing data values. They are categorized into different types based on the kind of data they hold.
Types of Variables:
String: Stores text, enclosed in double quotes (e.g., "Hello").
int: Stores whole numbers (integers), without decimals (e.g., 123, -123).
float: Stores floating-point numbers (numbers with decimals), requiring an f suffix (e.g., 19.99f, -19.99f).
char: Stores single characters, enclosed in single quotes (e.g., 'a', 'B').
boolean: Stores values with two states: true or false.
Declaring and Assigning Variables:
To create a variable, you must specify its data type and assign it a value using the following syntax:
Java
type variableName = value;
Examples:
string.
Java
String name = "John";
int.
Java
int myNum = 15;
Top comments (0)