日期:2014-05-20  浏览次数:20747 次

excuse me
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;



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


------解决方案--------------------
主要是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;
}
------解决方案--------------------
n错了.
------解决方案--------------------
for( ;i <=n;i++) -> for(; i <n; i++) //数组下标是从0到n-1,当i=n时数组越界