WAP to store ten numbers in an array by user input and search a number in the array.
import java.util.*;
class T14 {
public static void main(String[] args) {
int[] arr = new int[10];
int i, n, search;
boolean found = false;
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 numbers for the array: ");
for (i = 0; i < 10; i++) {
arr[i] = sc.nextInt();
}
System.out.println("Here is the array: ");
for (i = 0; i < 10; i++) {
System.out.println(arr[i]);
}
System.out.print("Enter the number to find in the array: ");
search = sc.nextInt();
for (i = 0; i < 10; i++) {
if (arr[i] == search) {
System.out.println(search + " is stored in the array at the index of " + i);
found = true;
}
}
if (!found) {
System.out.println("Given Number is not stored in the array!!");
}
}
}
Copy Code