2013-07-07 70 views
0

我想让用户将字符串分配给2个数组。然后,我希望他能够在分配后键入一个数字以提取分配给该字符串的值。ArrayIndexOutOfBoundsException尝试创建用户输入的数组列表时

import java.util.Scanner; 
public class Main { 

    public static void main (String[]args) { 

    Scanner keyboard = new Scanner(System.in); 

    String customerList[] = new String[2]; 

    customerList[1] = keyboard.nextLine(); 
    customerList[2] = keyboard.nextLine(); 


    System.out.println("Which array value would you like to see?"); 

    int listNum = keyboard.nextInt(); 

     System.out.println(customerList[listNum]); 
    } 

} 
+1

那么,有什么异常,你”重新获得? 'ArrayIndexOutOfBoundsException'? – Makoto

+0

是的,我解决了这个问题。甚至没有注意到我把1而不是0来开始数组。 – Ryan

回答