博德之门ctrl 8:Java高手请进!

来源:百度文库 编辑:高考问答 时间:2024/05/09 06:41:36
我定义了一个数组,现在想要从键盘给数组里的每个元素赋值,该写什么代码,输入的时候是连着输,还是输入一个按一次回车?

假设要输入10个数 其中ar为数组的名称
输入一次按一次回车.

try{
for(int i=0;i<10;i++)
{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
String s=reader.readLine();
ar[i]=Integer.parseInt(s);
}
}catch(IOException e)
{System.err.println(e.getMessage);}