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
Expected Output:
Input:
Enter 10 numbers: 10 20 30 40 50 60 70 80 90 100

Output:
Enter the number to find: 30
30 is stored in the array at the index of 2.