package chap1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class pgmidterm {
public static void main(String args[]) throws Exception {
BufferedReader fr = new BufferedReader (new InputStreamReader(System.in));
int score;
String subjectname[]={"國文科","英文科","管理數學"};
System.out.println("請輸入"+subjectname[0]+"成績");
score=Integer.parseInt(fr.readLine());
System.out.println(score);
---
package chap1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class pgmidterm {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int score[]={0,0,0};
String subjectname[]={"國文科","英文科","管理數學"};
for(int i=0;i<subjectname.length;i++) {
System.out.println("請輸入"+subjectname[i]+"成績");
score[i]=Integer.parseInt(br.readLine());
System.out.println(subjectname[i]+" 成績 = "+score[i]);
}}}
-------最後
package chap1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class pgmidterm {
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int score[]={0,0,0,0,0,0}, sum = 0 ;
String subjectname[]={"國文科","英文科","管理數學","統計學","會計學"};
for(int i=0;i<subjectname.length;i++) {
System.out.println("請輸入"+subjectname[i]+"成績");
score[i]=Integer.parseInt(br.readLine());
System.out.println(subjectname[i]+" 成績 = "+score[i]);
}
for(int i=0;i<subjectname.length;i++) {
sum= sum+score[i];
}
score[5]=sum;
System.out.println("總成績 = " + score[5]);
}}
留言列表