-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypes.java
More file actions
61 lines (41 loc) · 1.79 KB
/
DataTypes.java
File metadata and controls
61 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class DataTypes {
public static void main(String[] args) {
//Primitive Data Types
//Integer Types - For whole numbers
byte age = 25; // Integer (1 byte)
System.out.println("Age: " + age);
short year = 2024; // Integer (2 bytes)
System.out.println("Year: " + year);
int salary = 50000; // Integer (4 bytes)
System.out.println("Salary: $" + salary);
long population = 7800000000L; // Integer (8 bytes)
System.out.println("Population: " + population);
//Floating-Point Types - For numbers with decimals
float price = 19.99F; // Decimal (4 bytes)
System.out.println("Price: $" + price);
double pi = 3.14159265359; // Decimal (8 bytes)
System.out.println("Pi Value: " + pi);
//Character Type - For single characters
char grade = 'A'; // Character
System.out.println("Grade: " + grade);
//Boolean Type - For true/false values
boolean isJavaFun = true; // Boolean
System.out.println("Is Java Fun? " + isJavaFun);
//Non-primitive Data Types
//Strings - A sequence of characters
String name = "Sevenrishi Academy";
System.out.println("Welcome to " + name);
//Arrays - A collection of multiple values of the same type
int[] numbers = {10, 20, 30, 40};
System.out.println("First number: " + numbers[0]);
//Objects - Custom data types created using classes
class Student {
String name;
int age;
}
Student student = new Student();
student.name = "Saptarshi";
student.age = 20;
System.out.println(student.name + " is " + student.age + " years old.");
}
}