-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorld.java
More file actions
106 lines (87 loc) · 3.02 KB
/
HelloWorld.java
File metadata and controls
106 lines (87 loc) · 3.02 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package part;
public class HelloWorld {
public static void main(String[] args) {
//basics
System.out.println("Hello World");
//Data Types
displayNumericDataTypes();
displayBooleans();
displayCharacters();
practice();
}
public static void displayNumericDataTypes() {
byte minByteValue = Byte.MIN_VALUE;
byte maxByteValue = Byte.MAX_VALUE;
System.out.println("Min Byte: " + minByteValue);
System.out.println("Max Byte: " + maxByteValue);
short minShortValue = Short.MIN_VALUE;
short maxShortValue = Short.MAX_VALUE;
System.out.println("Min Short: " + minShortValue);
System.out.println("Max Short: " + maxShortValue);
int minIntValue = Integer.MIN_VALUE;
int maxIntValue = Integer.MAX_VALUE;
System.out.println("Min Int: " + minIntValue);
System.out.println("Max Int: " + maxIntValue);
long minLongValue = Long.MIN_VALUE;
long maxLongValue = Long.MAX_VALUE;
System.out.println("Min Long: " + minLongValue);
System.out.println("Max Long: " + maxLongValue);
float minFloatValue = Float.MIN_VALUE;
float maxFloatValue = Float.MAX_VALUE;
System.out.println("Min Float: " + minFloatValue);
System.out.println("Max Float: " + maxFloatValue);
double minDoubleValue = Double.MIN_VALUE;
double maxDoubleValue = Double.MAX_VALUE;
System.out.println("Min Double: " + minDoubleValue);
System.out.println("Max Double: " + maxDoubleValue);
//quick tip for readability
int hugeNumber1 = 281828373;
int hugeNumber2 = 281_828_373;
//notice the second number is easier to read for developers.
System.out.println("Huge Number: " + hugeNumber1);
System.out.println("Huge Number: " + hugeNumber2);
//run the code and notice that this doesnt affect how users view it.
/*
* Most preferred data types?
*
* Integer - is best for whole values
* Double - is best for floating pointer values
*
* */
}
public static void displayBooleans() {
boolean isValid = true;
boolean isNotValid;
if(isValid) {
isNotValid = false;
} else {
isNotValid = true;
}
System.out.println("Boolean (isValid): " + isValid);
System.out.println("Boolean (isNotValid): " + isNotValid);
}
public static void displayCharacters() {
char letter = 'a';
char letter2 = 'b';
char letter3 = 'c';
char unicode = '\u00A9';
System.out.println("Char Unicode: " + unicode);
int collection = letter + letter2 + letter3;
System.out.println("Char Number: " + collection);
String collectionStr = "" + letter + letter2 + letter3;
System.out.println("Char Letter: " + collectionStr);
char[] collectionArr = collectionStr.toCharArray();
for(char index: collectionArr) {
System.out.println("Char Array Letter: " + index);
}
System.out.println("Char Array Length: " + collectionArr.length);
}
public static void practice() {
byte numberByte = 125;
short numberShort = 32_000;
int numberInt = 1_288_723_283;
// long numberLong = 3_882_719_293L;
long sum = 50000 + 10 * (long)(numberByte + numberShort + numberInt);
System.out.println("\nSum: " + sum);
}
}