import java.lang.Math;
import java.util.Scanner;
class Arrays {
public static void main (String [] args) {
int A[]= {3, 1, 4, 5, 9, 2, 6, 8, 7, 0};
int Result;
System.out.print("Please enter a number from 1 to 9");
Scanner stdin = new Scanner (System.in);
int x = stdin.nextInt();
Result = x;
if(find(A,Result)!=-1)
{
System.out.println("Was found in this position");
System.out.print(find(A,Result));
}
else
System.out.println("Number not in array");
}
static int find (int A[], int N) {
for(int index = 0; index < A.length; index++)
if(A [index] == N )
{
return index;
}
return -1;
}
}
Reputation Points: 1536
Solved Threads: 431
Posting Expert
Offline 5,865 posts
since Aug 2005