统计信息

  • 访问数:14554
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P3Q8

2008-01-30 17:55:55

天气: 晴朗 心情: 高兴

/*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);
  }
}

加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd