-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx2DataType.java
More file actions
56 lines (49 loc) · 2.62 KB
/
Ex2DataType.java
File metadata and controls
56 lines (49 loc) · 2.62 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
package JavaEntry;
// For compile and create the class, first run in the command - (your-path/javac DataType.java)
// For run the compile class in the command - (your-path/java DataType)
public class Ex2DataType {
public static void main(String[] arg){
// Let's explore primitive datatype - Integer Type (byte, short, int, long), Floating Point(float, double), boolean and char
// Non-Primitive datatype - String, Arrays and Classes
// byte - Stores whole numbers from -128 to 127
// short Stores whole numbers from -32,768 to 32,767
// int Stores whole numbers from -2,147,483,648 to 2,147,483,647
// long Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
// float Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
// double Stores fractional numbers. Sufficient for storing 15 to 16 decimal digits
// boolean Stores true or false values
// char Stores a single character/letter or ASCII values
byte byteRupee = 100;
short shortNumber = 5000;
int intNumber = 10000;
long longNumber = 15000000000L;
float floatNumber = 35e3f;
double doubleNumber = 12E4d;
boolean isNumber = true;
boolean checkNumber = 10 < 5;
boolean isEqual = 10 == 5;
char charText = 'D';
char chatTextNumber = 65;
String wordText = "Primitive Data Type"; //non-primitive types typically starts with an uppercase
System.out.println("Byte Ex: " + byteRupee + ", ");
System.out.println("Short Ex: " + shortNumber + ", ");
System.out.println("Int Ex: " + intNumber + ", ");
System.out.println("Long Ex: " + longNumber + ", ");
System.out.println("Float Ex: " + floatNumber + ", ");
System.out.println("Double Ex: " + doubleNumber + ", ");
System.out.println("Boolean Ex: " + isNumber + ", ");
System.out.println("Boolean Ex 2: " + checkNumber + ", ");
System.out.println("Boolean Ex 3: " + isEqual + ", ");
System.out.println("Char Ex: " + charText + ", ");
System.out.println("Char Ex2: " + chatTextNumber + ", ");
System.out.println("String Ex2: " + wordText + ", ");
byte productQty = 20;
float productPrice = 75.00f;
float totalPrice = 1500.00f;
char rupee = '₹';
System.out.println("The product qty is " + productQty +
", the price of the product is " + productPrice +
", so total amount will be " + totalPrice +
", and the price need to pay in " + rupee);
}
}