(Finding the highest score) Write
a program that prompts the user to enter the number of students and each
student's name and score, and finally displays the student with the highest
score.
import java.util.Scanner;
public class lab5okt2014 {
public static void main(String[] args) {
int counter =1;
Scanner input = new Scanner(System.in);
System.out.println("sila masukkan jumpelajar");
int jum_p= input.nextInt();
System.out.println("sila masukkan nama dan markah");
String maxNama= nama;
int maxScore = score;
while(counter<=jum_p){
counter++;
System.out.println("sila masukkan nama dan markah pelajar");
nama = input.next();
score = input.nextInt();
if(score>maxScore){
maxScore=score;
maxNama=nama;
} // end utk if
} // end utk while
System.out.println("Pelajar dengan markah paling tinggi ialah : ");
System.out.println(maxNama+maxScore);
}
}
No comments:
Post a Comment