-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraySearching.java
More file actions
47 lines (37 loc) · 1.21 KB
/
arraySearching.java
File metadata and controls
47 lines (37 loc) · 1.21 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
46
47
import java.util.Scanner;
public class arraySearching{
public static void main(String[] args) {
int[] myArray = {12, 36, 96, 15, 85, 40, 18, 45, 36, 22, 10, 174, 18, 45, 45, 63};
Scanner input = new Scanner(System.in);
System.out.print("Enter Own Number : ");
int UserInput = input.nextInt();
boolean found = arraySearch(myArray, UserInput);
if (found) {
arrayMatchQuantity(myArray, UserInput);
}
}
public static boolean arraySearch(int[] array, int num){
int i = 0;
while (i < array.length) {
if (array[i] == num) {
System.out.println("Your Input is already available in array");
return true;
}
i++;
}
System.out.println("Your Input is not available in array");
return false;
}
public static int arrayMatchQuantity(int[] array, int num){
int i = 0;
int count = 0;
while (i < array.length) {
if (array[i] == num) {
count++;
}
i++;
}
System.out.println("Your Input is "+ count +" Times in array");
return count;
}
}