-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheck_data_type.java
More file actions
22 lines (17 loc) · 1.01 KB
/
Check_data_type.java
File metadata and controls
22 lines (17 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Check_data_type{
public static void main(String args[]) {
int intData = 15;
float floatData = 20.5f;
char charData = 'X';
Integer integerData = 25;
Double doubleData = 35.5;
String str = "Hello";
// show datatypes of variables by using getClass() and getSimpleName() methods
System.out.println(intData + " is of type " + ((Object)intData).getClass().getSimpleName());
System.out.println(floatData + " is of type " + ((Object)floatData).getClass().getSimpleName());
System.out.println(charData + " is of type " + ((Object)charData).getClass().getSimpleName());
System.out.println(integerData + " is of type " + integerData.getClass().getSimpleName());
System.out.println(doubleData + " is of type " + doubleData.getClass().getSimpleName());
System.out.println(str + " is of type " + str.getClass().getSimpleName());
}
}