Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

my prog is not print nextHighestScore  need help

Thread view: 
ba_lakov@hotmail.com - 29 Oct 2007 05:42 GMT
//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
Andrew Thompson - 29 Oct 2007 07:14 GMT
>//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?

Signature

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

Andrew Thompson - 29 Oct 2007 07:23 GMT
>>//this prog is  not print  nextHighestScore and i don't now way//
>>please help i;m a bigner thaks in adv
[quoted text clipped - 23 lines]
>
>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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.