forked from LaunchCodeEducation/java-web-dev-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayPractice.java
More file actions
30 lines (24 loc) · 977 Bytes
/
ArrayPractice.java
File metadata and controls
30 lines (24 loc) · 977 Bytes
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
public class ArrayPractice {
public static void main(String[] args) {
int[] numbers = {1, 1, 2, 3, 5, 8};
System.out.println("All array elements:");
for (int i : numbers) {
System.out.println(i);
}
System.out.println("only odd elements");
for (int i : numbers) {
if (i % 2 != 0)
System.out.println(i);
String inputString = "I would not, could not, in a box. I would not, could not with a fox. I will not eat them in a house. I will not eat them with a mouse.";
// Split the inputString using space as delimiter
String[] words = inputString.split(" ");
for (String word : words) {
System.out.println(word);
String[] sentences = inputString.split("//");
for (String sentence : sentences) {
System.out.println(word);
}
}
}
}
}