public class LinearSearch { public static void main(String[] args) { //build a random array int N = 20; int[] a = new int[N]; for (int i = 0; i < N; i++) a[i] = (int)(Math.random()*N); for (int i = 0; i < N; i++) System.out.print(a[i] + " "); System.out.println(); //input an integer int n = Integer.parseInt(args[0]); //loop from the first element to the last // if the current element is the same as the input // output the index and the value for (int i = 0; i < N; i++) { if (a[i] == n) { System.out.println("(" + i + ") " + n ); } } } }