-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.java
91 lines (76 loc) · 2.64 KB
/
Day2.java
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
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
public class Day2 {
public static void main(String[] args) {
// Array
String[] people = { "Matthew", "Jeremy", "Edgar" };
String[] newPeople = new String[10];
Object[] myObjectArr = { "matthew", 13, 'c' };
int[] numbers = new int[10];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}
// Way to print out values from the Array
System.out.println(Arrays.toString(numbers));
// ArrayLists
ArrayList<String> numbersSpelledOut = new ArrayList<String>();
numbersSpelledOut.add("one"); // index 0
numbersSpelledOut.add("two"); // index 1
numbersSpelledOut.add("three"); // index 2
numbersSpelledOut.add("four"); // index 3
System.out.println(numbersSpelledOut.get(1));
for (int i = 0; i < numbersSpelledOut.size(); i++) {
// System.out.println(numbersSpelledOut.get(i));
}
// For Each Loop
for (String num : numbersSpelledOut) {
// System.out.println(num);
}
// Hash Map
HashMap<String, String> ourHobbies = new HashMap<String, String>();
ourHobbies.put("Edgar", "Video Games");
ourHobbies.put("Justin", "Making Wine");
ourHobbies.put("Jeremy", "Cryptocurrency");
ourHobbies.put("Frank", "Sleep");
ourHobbies.put("Ozair", "Traveling");
ourHobbies.put("Taylor", "Running");
ourHobbies.put("Matt", "Photography");
ourHobbies.put("Zach", "WebFun");
System.out.println(ourHobbies.get("Edgar"));
for (String name : ourHobbies.keySet()) {
// System.out.println(name);
}
for (String name : ourHobbies.values()) {
// System.out.println(name);
}
for (HashMap.Entry<String, String> nameHobbies : ourHobbies.entrySet()) {
System.out.println("Key: " + nameHobbies.getKey() + ", Value: " + nameHobbies.getValue());
}
// Methods
// Get Max Value;
int[] someNums = { 1, 13, 33, 19, 102, 40, 9 };
// System.out.println(getMaxValue(someNums));
for (int i = 0; i <= someNums.length; i++) {
try {
System.out.println(someNums[i]);
} catch (Exception e) {
System.out.println(e);
}
}
}
public static int getMaxValue(int[] numbers) {
// Create A Max Value Variable To Hold the First of the Array
// Create a For Loop, Loop the Array
// Compare if the iterator value is greater than max value, replace max value
// with new value
// return max value
int greatestValue = numbers[0];
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] > greatestValue) {
greatestValue = numbers[i];
}
}
return greatestValue;
}
}