我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P3Q8
* Wang Chaoran
* Description:8 (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 P3Q8
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the number of students: ");
int number = scan.nextInt();
double highestScore=-1;
double score=-1;
String name1="",name2="";
for(int i=1; i<number+1;i++)
{
System.out.println("Please enter the students name: ");
name1 = scan.next();
System.out.println("Please enter the score of "+ name1+": ");
score = scan.nextDouble();
if(score >=highestScore)
{
highestScore = score;
name2 = name1;
}
}
System.out.println(name2+" is the one with the highest score of "+highestScore);
}
}
导入论坛查看(45)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing