- import java.util.Scanner;
- public class JPA05 {
- public static Scanner keyboard = new Scanner(System.in);
- public static void main(String args[]) {
- float sum = 0;
- System.out.print("請輸入學生人數:");
- int num = keyboard.nextInt();
- float score[] = new float[num];
- for (int i = 0; i < num; i++) {
- System.out.print("第" + (i + 1) + "個學生的成績:");
- score[i] = keyboard.nextFloat();
- sum = sum + score[i];
- }
- System.out.println("人數:" + num);
- System.out.println("總分:" + sum);
- System.out.println("平均:" + sum / num);
- }
- }
複製代碼 |