-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchNumber.java
More file actions
46 lines (36 loc) · 1.09 KB
/
Copy pathSearchNumber.java
File metadata and controls
46 lines (36 loc) · 1.09 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
public class SearchNumber {
int numarr[] = new int[10];
public void DisplayArray(int[] numarr) {
for (int i = 0; i < numarr.length; i++) {
System.out.println(numarr[i]);
}
}
public void Search(int[] numarr) {
int count = 0;
// for (int i = 0; i < numarr.length; i++) {
// if (numarr[i] == 100) {
// count++;
// System.out.println(+numarr[i] + " Found At Position Of the Index Number: " + (i + 1) + ".");
// }
//
// }
// System.out.println("--------------------------------------------------------");
// System.out.println("Count : " + count + " time that number is present in Array.");
int index = 0; // Tracks the current index
for (int num : numarr) {
if (num == 100) {
count++;
System.out.println(num + " Found At Position Of the Index Number: " + (index + 1) + ".");
}
index++; // Increment the index for the next iteration
}
// Optionally print the total occurrences found
System.out.println("Total occurrences of 100: " + count);
}
public int[] getNumarr() {
return numarr;
}
public void setNumarr(int[] numarr) {
this.numarr = numarr;
}
}