-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathExercise.java
More file actions
53 lines (45 loc) · 1.56 KB
/
Exercise.java
File metadata and controls
53 lines (45 loc) · 1.56 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
package com.booleanuk.core;
public class Exercise {
public int[] numsZeroToThree;
public int[] numsFiveToTen;
public int[] countdown;
public int[] favouriteNumbers = {1, 2, 4, 5, 7, 8, 10};
public String[] myHobbies = {"Fishing", "Language learning", "Skydiving", "Procrastinating"};
public void stepOne() {
// TODO: 1. Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array
numsZeroToThree = new int[4];
for (int i = 0; i < 4; i++) {
numsZeroToThree[i] = i;
}
}
public void stepTwo() {
// TODO: 2. Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array
numsFiveToTen = new int[6];
for (int i = 0; i < 6; i++) {
numsFiveToTen[i] = i + 5;
}
}
public void stepThree() {
// TODO: 3. Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array
countdown = new int[4];
int j = 3;
for (int i = 0; i < 4; i++) {
countdown[i] = j;
j--;
}
}
public boolean stepFour(int num) {
// TODO: 6. Write a for loop that checks if num is in the favouriteNumbers array
for (int n: favouriteNumbers){
if (n==num) return true;
}
return false;
}
public boolean stepFive(String hobby) {
// TODO 5. Write a for loop that checks if the hobby String is in the myHobbies array
for (String h: myHobbies){
if (h.equals(hobby)) return true;
}
return false;
}
}