Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help with Indexes

 
Jim Wysocki
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to assign values to corresponding Indexes. I'm using the find method but all of the printouts show the last entered item for each index. The math is correct but there's a bug in the code i can't figure out.


Marilyn added code tags
[ October 30, 2002: Message edited by: Marilyn de Queiroz ]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please write a smaller program which shows the problem, or point out where in this piece of code you are seeing the problem. And give a specific example. Like:
items[1] contains the value "tree", instead of "tower".
 
Amy Snow
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I am doing the same project in my ISYS 216 class at FSU. I'm in the 9:00 class. The only thing I noticed with your program is that u need braces for the if statements in the find() method and both of the store() methods.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amy is correct, although in the find method it is less important because you only have one line after the if statement. In both of the other two methods you'll only execute the first line after the if statement if it is true, the other two following lines will always be executed.
Putting the braces around the if statement (Even if it is only one line) is not a bad idea to get into. If you really hate them on one liners then put the line to be executed on the same line as the if statement itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic