Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I/O problem

 
andrew cassato
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble reading data from a file called data.txt and storing it as an array of fractions...


i use the debugger and see that it is taking data in and assigning to numerator and denominator but it never gets stored in the array. for some reason it is always showing i = 0 even though i have the i++, so i have no idea why its not incrementing.

Thanks in advance for any help.
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
move int i = 0; outside the while loop
Check with system.out.println it will help you to know the i value inside the while loop.

And one suggestion use finally block to close the scanner.

Regards,
Sriram.V
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint :
 
Suresh Sajja
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in While loop, for each iteration, you are re-initializing i to 0
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic