-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrieve specified element from array.java
More file actions
47 lines (37 loc) · 1.33 KB
/
retrieve specified element from array.java
File metadata and controls
47 lines (37 loc) · 1.33 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
import java.util.Arrays;
import java.util.Scanner;
public class RetrieveElements {
public static void main(String[] args) {
int value;
int element;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of elements you want in the array: ");
value = input.nextInt();
int array[] = new int[value];
System.out.println("Enter all the elements: ");
for(int i = 0; i < value ; i++) {
array[i] = input.nextInt();
}
System.out.println("Enter the element you want: ");
element = input.nextInt();
Arrays.sort(array);
boolean Elementwanted = false;
for (Integer number : array) {
if (number.equals(element)) {
Elementwanted = true;
int elements[] = null;
int count = 0;
if ( Elementwanted = true) {
for (int i = 0; i < array.length; i++) {
for (element = i + 1 ; element < array.length; element++) {
if (array[i] == elements[element]) {
count = count + 1;
System.out.println("Duplicated: " + count + "The element you searched for:" + element);
}
}
}
}
}
}
}
}