Your code is quite weak:
- class names start with capital letter. Always!
- each code line has to end with a ";"
- init and assign variables as you need them - in the loop-header, when asking for a value. That limits the scope (not here in the example, but in general)
- the for-loop:
- all being beside of humans do count from 0. Do so too please.
- a loop with 5 elements is counted therefore from 0-4 (end condition "<5" is preferable over "<=4").
public class Location_of_an_element_in_array {
public static void main(String[] args) {
int arr[] = new int[5];
Scanner input = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
System.out.println("Enter number:");
arr[i] = input.nextInt();
}
System.out.println("\nWhich number's location you want to search?");
int search = input.nextInt();
}
}
Now the code runs.
Please use Eclipse or Netbeans for coding - both IDE will guide you through the process! There is no reason not to use one of them.
This is a homework task. You will have to add the search yourself. Please ask when you get stuck in that, also debugging the code can help you a lot (google for that according to the IDE you're using).
Have fun!