日期:2014-05-20 浏览次数:20976 次
....
for (int i = 0; i < 3; i++) {
str[3][i] = in.readLine();
}
....
------解决方案--------------------
错误的原因是数组没有创建,为什么要用二维呢?
修改成一维数组的实现如下:
public class Test {
public static void main(String args[])throws IOException{
String str[]=new String[3];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i <3;i++){
str[i]=in.readLine(); //显示这里有问题,为什么?谢谢~~
}
for(int i=0;i <3;i++){
System.out.println(str[i]);
}
}
}
------解决方案--------------------
你需要给输入的每个字符串分配空间,new string(输入字符串的长度)才行
------解决方案--------------------
你的数组的概念一塌糊涂,上面创建的是二维数组,下面赋值是给一维数组,怎么可能会对呢?
------解决方案--------------------
错误的原因是数组没有创建,为什么要用二维呢?
修改成一维数组的实现如下:
Java code
public class Test { public static void main(String args[])throws IOException{ String str[]=new String[3]; BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); for(int i=0;i <3;i++){ str[i]=in.readLine(); //显示这里有问题,为什么?谢谢~~ } for(int i=0;i <3;i++){ System.out.println(str[i]); } } }
------解决方案--------------------
关注下