I'm ready to pull out my hair. I'm pretty new to this so it's probably something really simple. Can anyone tell me why I can't enter any key larger than 10? I get the out of bounds message. What's suppose to happen is I enter an index and the search displays the integer at that index. Here's the part of the code where I know the problem exists.
Thanks, Lynn
//Main Method public static void main(String[] args) { ArrayDemo frame = new ArrayDemo(); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setSize(230, 120); }
public int linearSearch(int key, int[] list) { key = Integer.parseInt(jtfIndex.getText()); list = new int[100]; for(int counter = 0;counter < list.length;counter++) list[counter] = (int)(Math.random() * 10);