I have not experimented with binary searches and things like that so my code is using a simpler way. The value I'm searching for is 9 which is found at index position 4 but my program is reporting that the value is found at index position 9. There is something I'm doing wrong here:
public class SearchArrayForValue { public static void main(String args[]) { int numbers[] = {2, 5, 7, 8, 9, 11}; int value = 9; int i; int j; System.out.print("The values in the array are: "); for(i = 0; i < 6; i++) System.out.print(numbers[i] + " "); for(j = 0; j < 6; j++) if(numbers[j] == value) break; System.out.println("\nValue of " + value + " found at index position " + numbers[j]); } }