fix: OneOne

This commit is contained in:
Sami 2024-11-13 09:59:50 -05:00
parent f8748fcbdf
commit c93a26c059
2 changed files with 28 additions and 0 deletions

BIN
FindtheOne/FindTheOne.class Normal file

Binary file not shown.

View 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;
}
}