我正在尝试在节点中存储一组int。我没有按照我应该的方式获得节点。任何人都可以提供任何帮助都会很棒。
public void readIn()
{
int counter = 1;
try {
Scanner inFile = new Scanner(new FileReader("WordProblemData.txt"));
int times = Integer.parseInt(inFile.next());
for (int a = 1;a <= times; a++)
{
for (int i = 1; i <= 8; i++)
{
num[i-1] = Integer.parseInt(inFile.next());
System.out.println(num[i-1]);
}
data = (String)(inFile.next());
System.out.println(data);
head = new DateStampNode(data,num,head);
}
inFile.close();
答案 0 :(得分:0)
除非你有一个预先分配的大型数组,否则我认为你需要在填充之前分配一个新的数组。
您可能还想记住增加num
。
答案 1 :(得分:0)
我不确定你的问题究竟是什么(你认为应该?),但可能是这样:
int[] num = new int[8]; //you should allocate a new array, otherwise you'd overwrite the values in the next iteration of the outer loop
for (int i = 1; i <= 8; i++)
{
num[i-1] = Integer.parseInt(inFile.next());
System.out.println(num[i-1]);
}
data = (String)(inFile.next());
System.out.println(data);
//you're storing num here, so you'd need a new num array for the next iteration, see above
head = new DateStampNode(data,num,head);