Skip to content

Commit 2642397

Browse files
committed
Array challenges
1 parent 794c9a0 commit 2642397

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/arrays/challenges.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,79 @@ Remember the rules for this are
66
- Try not to give up until you've given it a solid attempt
77

88
## Challenge 1
9+
10+
Edit the following program so that the output is zero.
11+
12+
```java
13+
void main() {
14+
// Only change this line
15+
String[] words = { "Sam", "I", "Am" };
16+
System.out.println(array.length);
17+
}
18+
```
19+
20+
## Challenge 2
21+
22+
Using only `System.out.println` and array accesses,
23+
print `hello world` to the screen.
24+
25+
```java
26+
void main() {
27+
char[] letters = {
28+
' ',
29+
'h',
30+
'e',
31+
'l',
32+
'o',
33+
'w',
34+
'r',
35+
'd'
36+
};
37+
38+
// Your code here
39+
}
40+
```
41+
42+
## Challenge 3
43+
44+
Without editing either the array declaration or the loop at the bottom,
45+
make the output of this program `0`.
46+
47+
```java
48+
void main() {
49+
final int numbers = { 1, 2, 3, 4 };
50+
51+
// -----------
52+
// YOUR CODE HERE
53+
54+
55+
// -----------
56+
int total = 0;
57+
int index = 0;
58+
while (index < numbers.length) {
59+
total += numbers[index];
60+
index += 1;
61+
}
62+
System.out.println(total);
63+
}
64+
```
65+
66+
## Challenge 4
67+
68+
Make this program output `bulbasaur` without changing anything
69+
above or below the marked areas.
70+
71+
```java
72+
void main() {
73+
char[] name = { 'b', 'u', 'l', 'b' };
74+
75+
// -----------
76+
// YOUR CODE HERE
77+
78+
79+
// -----------
80+
char[] toPrint = name;
81+
System.out.println(toPrint);
82+
}
83+
```
84+

src/user_input

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)