Data types and variables
Understanding data types
In programming, data types are used to classify different types of data. Here are some common data types:
Integer:
int age = 25;
Floating-point:
double pi = 3.14;
Boolean:
boolean isTrue = true;
Character:
char letter = 'a';
String:
String name = "Alice";
Declaring and initializing variables
Variables are used to store data in a program. Here's an example of how to declare and initialize variables in Java:
Basic arithmetic operations
Arithmetic operations are used to perform mathematical calculations in a program. Here are some examples
In the above examples, int
and double
are data types used to represent integer and floating-point numbers, respectively. The arithmetic operators (+
, -
, *
, /
, and %
) are used to perform addition, subtraction, multiplication, division, and modulus (remainder) operations, respectively.
Last updated