The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Program won't go to result after input. Help ASAP please..

I have to create a program that takes a list of student names and grades and then takes the 2 highest scores and reads them, but the result won't show. I'm pretty sure it's because I'm not sure about how to code the last part which should output the results. Here's my code. Help please and thank you.

Re: Program won't go to result after input. Help ASAP please..

Enter number of students in class:4
Enter student's name: R
Enter student's grade:98
Enter student's name: L
Enter student's grade:99
Enter student's name: E
Enter student's grade:91
Enter student's name: C
Enter student's grade:95
The student with the highest grade is C with a 95.0
The student with the second highest grade is with a 0.0

I guess it shows the results (last 2 lines), but now it's just showing the highest grade as the last input and not entirely sure how to go about saving all the inputs on this problem so I can do both the highest and 2nd highest grades.

Re: Program won't go to result after input. Help ASAP please..

I guess it shows the results (last 2 lines), but now it's just showing the highest grade as the last input and not entirely sure how to go about saving all the inputs on this problem so I can do both the highest and 2nd highest grades.

before that create a variable that will handle your highest grade and equate it to zero, let say it's double finalGrade
and whenever you get a grade higher than variable finalGrade,
replace its value by what you got.
(Same process for student's name)

Re: Program won't go to result after input. Help ASAP please..

Your loop iterates numberStudents times but it stores all the values in the same variables, hence there are only 1 set of values with you when the loop ends and that is the last value entered. This is the reason that even after entering values like 98 you are getting 95 as the max value(because it was entered last).