aspose file tools*
The moose likes Beginning Java and the fly likes Need help with output of a program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with output of a program" Watch "Need help with output of a program" New topic
Author

Need help with output of a program

Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
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

Joined: Feb 08, 2009
Posts: 606

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!


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Andrew Albers
Greenhorn

Joined: Feb 19, 2009
Posts: 10
Thanks for pointing that out got it to work now. the help was much appreciated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Need help with output of a program