【发布时间】:2014-03-18 18:34:06
【问题描述】:
我必须从一个外部文件中读取一个数字列表并将它们插入到自己的数组中,以确定它们是正数还是负数。扫描仪可以很好地读取数字,但是当将它们插入数组时就会出错。如您所见,下面是我的代码和输出。文件中的内容打印在输出中,但是当我要求它打印数组时,就是字母/数字/符号的混乱。谁能帮我修一下?
public class Numbers {
public static void main(String[] args) throws IOException {
Scanner reader = new Scanner(new FileInputStream("First.dat"));
int Positive[] = new int[20];
int Negative[] = new int[20];
int X = 0;
int Y = 0;
while (reader.hasNextInt()) {
int Start = reader.nextInt();
System.out.println(Start);
if (Start < 0) {
Negative[X] = Start;
X += 1;
}
if (Start > 0) {
Positive[Y] = Start;
Y += 1;
}
}
System.out.println(Positive + " " + Negative);
}
}
输出:
3
66
54
-8
22
-16
-56
19
21
34
-34
-22
-55
-3
-55
-76
64
55
9
39
54
33
-45
[I@1b41650 [I@24e11c
【问题讨论】:
-
您希望它打印什么?为什么?
-
我希望它打印出我插入数字的数组
-
想要 如果您不知道自己在做什么,则无关紧要。你做了什么,你为什么要这样做?你为什么不做点别的?
标签: java