Question: JAVA Activity 3: Search for the location of a specific element Write a program that allows the user to enter 5 numbers and a number
JAVA Activity 3: Search for the location of a specific element Write a program that allows the user to enter 5 numbers and a number to be searched, then the program displays the position (index) of this number in the array, if it does not exist, it returns -1, the program effect is as shown below

The basic structure of the program is shown below, complete with other codes to achieve the above functions.
public class SearchNumberIndex { public static void main(String[] args) { Scanner input = new Scanner( System.in ); System.out.println("Enter 5 numbers:"); int[] nums = new int[5]; for (int i = 0; i
System.out.println("Enter a number to search:");
int n = input.nextInt();
//other codes
}
}
Enter 5 numbers: 34 54 12 9 8 Enter a number to search: 12 Found it in the index: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
