-
Notifications
You must be signed in to change notification settings - Fork 8
/
HowMany.java
36 lines (32 loc) · 979 Bytes
/
HowMany.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
35
36
import java.util.ArrayList;
import java.util.Scanner;
public class MoreThanOnce {
public static boolean moreThanOnce(ArrayList<Integer> list, int searched) {
// write your code here
int i = 0;
for (int l :list){
if (l == searched){
i++;
}
}
if (i > 1){
return true;
}
return false;
}
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(3);
list.add(2);
list.add(7);
list.add(2);
System.out.println("Type a number: ");
int number = Integer.parseInt(reader.nextLine());
if (moreThanOnce(list, number)) {
System.out.println(number + " appears more than once.");
} else {
System.out.println(number + " does not appear more than once. ");
}
}
}