static Object[] get()
{
Object[] list = new Object[10];
int i=0;
System.out.println("please input parame");
do
{
InputStreamReader isr = new InputStreamReader(System.in); 
BufferedReader br = new BufferedReader( isr );
try {

list[i] = br.readLine();
} catch (IOException e) {

e.printStackTrace();
  } }while(list[i]!="#");

for(i = 0; i<10; i++)
System.out.println("list["+i+"]="+list[i]);

return list;

}
请问有什么问题啊?运行不成功.

解决方案 »

  1.   

    主要是while (!list[i++].equals("#"));这里static Object[] get() {
    Object[] list = new Object[10];
    int i = 0;
    System.out.println("please input parame");
    do {
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    try { list[i] = br.readLine();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (ArrayIndexOutOfBoundsException e) {
    break;
    }
    } while (!list[i++].equals("#")); for (i = 0; i < 10; i++)
    System.out.println("list[" + i + "]=" + list[i]);
    return list;
    }
      

  2.   

    public static void main(String[] args) {
    Object a[]=null;
    a=get();
    Perm(a,0,2);

    }
    static Object[] get()
    {
    System.out.println("please input num");
    InputStreamReader isr = new InputStreamReader(System.in); 
    BufferedReader br = new BufferedReader( isr );

         int n=0;
    try {
    n = Integer.parseInt(br.readLine());
    } catch (NumberFormatException e1) {

    e1.printStackTrace();
    } catch (IOException e1) {

    e1.printStackTrace();
    } Object[] list = new Object[n];
    int i=0;
    System.out.println("please input parame");
    for( ;i<=n;i++)
    {
        isr = new InputStreamReader(System.in); 
     br = new BufferedReader( isr );
    try {

    list[i] = br.readLine();
    } catch (IOException e) {

    e.printStackTrace();
      } }

    for(i = 0; i<list.length; i++)
    System.out.println("list["+i+"]="+list[i]);

    return list;

    }
    就有Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
    错误.
      

  3.   

    把ArrayIndexOutOfBoundsException这个catch了直接break出for
      

  4.   

    for( ;i<=n;i++) -> for(; i<n; i++) //数组下标是从0到n-1,当i=n时数组越界了