-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexOf.java
34 lines (24 loc) · 1.17 KB
/
IndexOf.java
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
import java.util.ArrayList;
import java.util.Scanner;
public class IndexOf {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
while (true) {
int input = Integer.valueOf(scanner.nextLine());
if (input == -1) {
break;
}
list.add(input);
}
System.out.println("");
// implement here finding the indices of a number
System.out.println("Search for? ");
int search = Integer.valueOf(scanner.nextLine());
for(int i = 0;i < list.size(); i++) {
if(search == list.get(i)) {
System.out.println(search + " is at index " + i);
}
}
}
}