Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with output of a program

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing that out got it to work now. the help was much appreciated.
 
reply
    Bookmark Topic Watch Topic
  • New Topic