Variables and DataTypes
In programming, variables are used to store data that can be referenced and manipulated throughout the program. Each variable has a data type, which defines the type of data it can store.
Common data types in Java include:
- int: Integers are used for storing integers (whole numbers 0-9).
- double: Doubles are used for storing floating-point/decimal numbers (0.1, 1.2).
- char: Characters are used for storing single characters ('A', 'B', 'C').
- float: Floats are used for storing positive and negative numbers with a decimal point (5.5, 0.25, -103.342).
- boolean: Booleans are used for storing true or false values.
Above are some code samples in java creating an integer, double, character, and float variables.
Quiz
-
Create a variable named x that is an integer and has a value of 3.
-
Create a variable named change that is a double and has a value of 5.07
-
Create a variable named grade that is a character and has a value of A.