public class LinearSearch_Repeat { public static void printArray(int[] a) { System.out.print("\nIndex i: "); for(int i=0; i< a.length; i++) System.out.printf("%2d, ", i); System.out.print("\nElement a[i]: "); for(int i=0; i< a.length; i++) System.out.printf("%2d, ", a[i]); System.out.println("\n\n"); } public static void main(String[] args) { int[] a= { 4, 21, 36, 14, 62, 91, 8, 62, 7, 81, 62, 10}; printArray(a); // Now do the Linear Search int target = 62; //int target = 72; // Try this target next int[] idx = new int[5]; for(int i=0; i< idx.length; i++) idx[i]= -1; int count=0; System.out.println("\nSearching for target=" + target + " ..."); for(int i=0; i< a.length; i++) { if(a[i] == target) { idx[count]=i; count++; } } if(count == 0) System.out.println("Target not found."); else { for(int j=0; j< count; j++) System.out.println("Target found at index: " + idx[j]); } } }