-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw7_hw02_hw27.java
40 lines (38 loc) · 1.16 KB
/
w7_hw02_hw27.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.*;
public class w7_hw02_hw27 {
public static BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
System.out.print("輸入學生人數:");
int n = Integer.parseInt(buf.readLine());
String name[] = new String[n];
double score[] = new double[n];
input_data(name, score);
show(name, score);
}
public static int input_data(String name[], double score[]) throws IOException {
for (int q=0; q<name.length; q++) {
System.out.print("輸入學生名稱:");
name[q] = buf.readLine();
score[q] = input_score();
}
return name.length;
}
public static double input_score() throws IOException {
double score;
while (true) {
System.out.print("輸入總平均的分數:");
score = Double.parseDouble(buf.readLine());
if (score >= 0 && score <= 100) {
break;
}
System.out.println("輸入格式錯誤,請重新輸入。");
}
return score;
}
public static void show(String name[], double score[]) {
System.out.println("學生名稱\t總平均");
for (int q=0; q<name.length; q++) {
System.out.println(name[q]+"\t\t"+score[q]);
}
}
}