Java 乙班2/26作業

Main

import java.util.*;
public class Java_Testing
{

 public static void main(String[] args)
 {
  // TODO 自動產生的方法 Stub
  Scanner scan = new Scanner(System.in);
  System.out.print("請輸入人數:");
  int count = scan.nextInt();
  Data[] datas = new Data[count];
  int max = 0, avg = 0;
  for (int i = 0; i < datas.length; i++)
  {
   datas[i] = new Data();
   datas[i].id = i + 1;
   System.out.print("請輸入名子:");
   datas[i].name = scan.next();
   System.out.print("請輸入分數:");
   datas[i].score = scan.nextInt();
   if (datas[i].score >= max)
    max = datas[i].score;
   avg += datas[i].score;
  }
  avg /= datas.length;
  System.out.println("平均:" + avg);
  for (int i = 0; i < datas.length; i++)
  {
   if (datas[i].score == max)
    System.out.println(datas[i].id + " " + datas[i].name);
  }
 }

}


Class

public class Data
{
 int id;
 String name;
 int score;
}

留言

這個網誌中的熱門文章

C# 井字遊戲