Today you will learn:
int, double, boolean, char)By the end, you will be able to store and use data in Java programs.
Primitive types are basic data types in Java.
int → whole numbers (e.g., 5, 20)double → decimal numbers (e.g., 1.75)boolean → true or falsechar → single character (e.g., 'A')Strings are used to store text.
String name = "Alice";
Strings are not primitive types, but they are used very often.
To create a variable, you specify its type and name.
int age = 20;
double height = 1.75;
boolean isStudent = true;
char grade = 'A';
String name = "Alice";
Explanation:
=You can use variables to display information.
System.out.println(name + " is " + age + " years old.");
This combines text and variables into one output.
Sometimes you need to convert one data type into another.
Example:
double price = 9.99;
int roundedPrice = (int) price;
Explanation:
(int) converts the double into an integer
int age = 20;
double height = 1.75;
boolean isStudent = true;
char grade = 'A';
String name = "Alice";
System.out.println(name + " is " + age + " years old.");
Create a program that calculates the area of a rectangle.
Steps:
Example:
public class Rectangle {
public static void main(String[] args) {
double width = 5.0;
double height = 3.0;
double area = width * height;
System.out.println("Area: " + area);
}
}