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:
// Declare and initialize an integer variableintage=25;// Declare and initialize a double variabledoublepi=3.14;// Declare and initialize a boolean variablebooleanisTrue=true;// Declare and initialize a character variablecharletter='a';// Declare and initialize a string variableStringname="Alice";
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.