fix: OneOne
This commit is contained in:
parent
f8748fcbdf
commit
c93a26c059
BIN
FindtheOne/FindTheOne.class
Normal file
BIN
FindtheOne/FindTheOne.class
Normal file
Binary file not shown.
28
FindtheOne/FindTheOne.java
Normal file
28
FindtheOne/FindTheOne.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FindTheOne
|
||||||
|
* given an array of ints, find the one that start with 1
|
||||||
|
*/
|
||||||
|
public class FindTheOne {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int[] arr = { 1, 23, 123, 45, 67, 176 };
|
||||||
|
System.out.println(OneOne(arr));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> OneOne(int[] arr) {
|
||||||
|
List<String> Ones = new ArrayList<>();
|
||||||
|
String[] Convereted = new String[arr.length];
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
Convereted[i] = String.valueOf(arr[i]);
|
||||||
|
}
|
||||||
|
for (String str : Convereted) {
|
||||||
|
if (str.startsWith("1")) {
|
||||||
|
Ones.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Ones;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user