开发者

Storing a complete Array in a node

I am trying to store an array of ints in a node. I am not getting the node the way i should.开发者_StackOverflow中文版 Any help anyonecould give will be great.

  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(); 


Unless you have a large, preallocated array, I believe you need to allocate a new array before filling it.

You may also want to remember to increment num.


I'm not sure what your problem really is (what should you get in your opinion?), but it might be this:

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜