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

JAVA Activity 3: Search for the location of a specific element Write

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!