-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion129_CopyCertainValues.java
More file actions
61 lines (33 loc) · 1.19 KB
/
Question129_CopyCertainValues.java
File metadata and controls
61 lines (33 loc) · 1.19 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
54
55
56
57
58
59
60
61
package week7_Array_2D_ArrayList;
import java.util.Arrays;
public class Question129_CopyCertainValues {
public static void main(String[] args) {
// olcay // Jul 24, 2020
/* Given a String array arr with the following elements
["zero", "one", "two","three","four"]
Create another array fewValues and copy words that have letter "e" in them
You need to know how many element contain "e" and create array accordingly
Values in fewValues array need to be["zero", "one","three"]
*/
System.out.println("-----EXAMPLE RUN ---------");
String[] numbers = {"zero", "one", "two","three","four"};
System.out.println(Arrays.toString(getWithE(numbers)));
}
public static String[] getWithE(String[] arr) {
int count=0;
for(String values : arr) {
if(values.contains("e")) {
count++;
}
}
String[] fewValues = new String[count];
String str="";
for(String values : arr) {
if(values.contains("e")) {
str+=values+" ";
}
}
fewValues = str.split(" ");
return fewValues;
}
}