-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03DataTypes.java
More file actions
37 lines (33 loc) · 1.19 KB
/
03DataTypes.java
File metadata and controls
37 lines (33 loc) · 1.19 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
class DataTypes {
public static void main(String[] args) {
// Primitive Data Types
byte myByte = 1;
int myInt = 100;
short myShort = 10;
long myLong = 1000L;
float myFloat = 10.5f;
double myDouble = 99.99;
char myChar = 'A';
boolean myBoolean = true;
// Non-Primitive Data Types
String myString = "Hello, Java!";
int[] myArray = {1, 2, 3, 4, 5};
Object myObject = new Object();
// Printing Primitive Data Types
System.out.println("Byte: " + myByte);
System.out.println("Short: " + myShort);
System.out.println("Long: " + myLong);
System.out.println("Float: " + myFloat);
System.out.println("Integer: " + myInt);
System.out.println("Double: " + myDouble);
System.out.println("Character: " + myChar);
System.out.println("Boolean: " + myBoolean);
// Printing Non-Primitive Data Types
System.out.println("String: " + myString);
System.out.print("Array: ");
for (int num : myArray) {
System.out.print(num + " ");
}
System.out.println("\nObject: " + myObject.toString());
}
}