my prog is not print nextHighestScore need help

B

ba_lakov

//this prog is not print nextHighestScore and i don't now way//
please help i;m a bigner thaks in adv


import java.util.Scanner;

public class C4E909
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int studentScore;
String studentName;
int highestScore = 0;
int nextHighestScore = 0;
String studentNameHighestScore = "";
String studentNameNextHighestScore = "";
int numberOfStudents;

System.out.println("Please enter the number of students to process:");
numberOfStudents = keyboard.nextInt();

for(int i = 0; i < numberOfStudents; ++i)
{
System.out.println("Please enter the student name:");
studentName = keyboard.next();
System.out.println("Please enter the student score:");
studentScore = keyboard.nextInt();
if(studentScore > highestScore)
{
highestScore = studentScore;
studentNameHighestScore = studentName;
}//end if


if((studentScore < highestScore) && (studentScore > nextHighestScore))
{
System.out.println("HERE");
nextHighestScore = studentScore;
studentNameNextHighestScore = studentName;
}//end if

}

System.out.println("Name highest score: " + studentNameHighestScore);
System.out.println("Highest score: " + highestScore);

System.out.println("Name next highest score: " +
studentNameNextHighestScore);
System.out.println("Next highest score: " + nextHighestScore);

}//end main
}//end class
 
A

Andrew Thompson

//this prog is not print nextHighestScore and i don't now way//
please help i;m a bigner thaks in adv

[output 1]
Please enter the number of students to process:
3
Please enter the student name:
a
Please enter the student score:
3
Please enter the student name:
b
Please enter the student score:
2
HERE
Please enter the student name:
c
Please enter the student score:
1
Name highest score: a
Highest score: 3
Name next highest score: b
Next highest score: 2
Press any key to continue . . .
[/output 1]

Can you tell why it is different to your output?

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 
A

Andrew Thompson

Andrew said:
//this prog is not print nextHighestScore and i don't now way//
please help i;m a bigner thaks in adv

[output 1]
Please enter the number of students to process:
3
Please enter the student name:
a
Please enter the student score:
3
Please enter the student name:
b
Please enter the student score:
2
HERE
Please enter the student name:
c
Please enter the student score:
1
Name highest score: a
Highest score: 3
Name next highest score: b
Next highest score: 2
Press any key to continue . . .
[/output 1]

Can you tell why it is different to your output?

Or, more accurately, *this* output - when both came
from the 'exact'* same original code you posted.

[output 2]
Please enter the number of students to process:
3
Please enter the student name:
a
Please enter the student score:
1
Please enter the student name:
b
Please enter the student score:
2
Please enter the student name:
c
Please enter the student score:
3
Name highest score: c
Highest score: 3
Name next highest score:
Next highest score: 0
Press any key to continue . . .
[output 2]

* At least, the exact same code as I ran, after I
had formatted it with normal indentation. I do not
believe any other changes were made.

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,184
Members
46,721
Latest member
DollieSawt

Latest Threads

Top