
write java program to enter five numbers and will determine the location of the number
sample output:
ENTER 5 NUMBERS: 1 2 3 4 5 ENTER NUMBER TO SEARCH:1{press enter} 1 found in index 0

import java.util.*;
class ArrayExample
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int array[]=new int[5];
System.out.println("Enter Array Elements: ");
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();
}
System.out.println("Enter number to search: ");
int number=input.nextInt();
System.out.println("Its index is: ");
for(int i=0;i<array.length;i++){
if(array[i]==number){
System.out.print(i);
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.