• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with output of a program

 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the goal of the program is to get it to print out the top two students scores that works fine. the program asks for the number of students first (I've been using 3 for simplicity), then you enter the student name and then the score. your supposed to do this until you hit the number of students you wanted to enter, but for some reason if i enter a number it either goes one up (so 4 instead of 3). i believe the problem might be in line 25, just curious about what i did wrong...
Also does anyone recommend any good java writing software. right now i have netbeans, jcreator and Textpad.





 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the code is a bit messy.

Line 12-18 takes the score for 2 students - that you take as you initial high score.

Inside the for loop,
Line 28-31 & 33-37 take two student input - which means you code will always ask for even number of inputs. Hence when you put in 3 you will get either '2' or '4' depending on if you use '<' or '<=' in you for loop.
This ratio will get more and more skewed as number of inputs increases.

Re-Look at you logic - Try hand running it and you'll see what you are doing wrong.

As for editors - For someone new I always suggest a stint of hand coding - notepad and the command line.
Other than that Jcreator and Textpad should be fine for starts!
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have same (duplicate) code in it. Try to implement it without the duplicate code (may moving them to a method/class) or change your logic so that you don't need those duplicate code. And about editors, eclipse would be a good choice when you get the basics of Java right.
 
Andrew Albers
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing that out got it to work now. the help was much appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic