-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathArray.java
More file actions
53 lines (34 loc) · 1.32 KB
/
Array.java
File metadata and controls
53 lines (34 loc) · 1.32 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
package exercises;
import java.util.*;
public class Array {
public static void main(String[] args) {
int[] intArray = {1, 1, 2, 3, 5, 8};
for (int i : intArray) {
if ( i%2 == 1 ) System.out.println(i);
}
String phrase = "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.";
String[] words = phrase.split(" ");
System.out.println(Arrays.toString(words));
String[] sentences = phrase.split("\\.");
System.out.println(Arrays.toString(sentences));
}
public static void main(ArrayList<String> arr) {
Scanner input = new Scanner(System.in);
String str = "Java convert String to ArrayList";
// split string by no space
String[] strSplit = str.split("");
// Now convert string into ArrayList
ArrayList<String> strList = new ArrayList<>(
Arrays.asList(strSplit));
// Now print the ArrayList
for (String s : strList) {
System.out.println(s);
System.out.println("Enter a word length: ");
int numChars = input.nextInt();
if (numChars == s.length()) {
System.out.println(s);
}
}
}
}