JAVA/4. Array
배열예제 10 (점수관리 배열2)
날아올라↗↗
2016. 6. 22. 15:50
728x90
반응형
- package test.com;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- public class Test05score2 {
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- InputStream is = System.in;
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- System.out.println("[성적처리 프로그램]");
- //총인원 3명의 명단도 배열로 처리하시오.
- //국,영,수 성적처리 프로그램을 작성하시오.
- //과목과 점수는 배열을 사용하시오.
- //출력은 반복문을 사용하시오.
- int totalCount = 3;
- String[] names = new String[totalCount];
- names[0] = "KIM";
- names[1] = "";
- names[2] = "";
- int subjectCount = 3;
- String[] subjects = new String[subjectCount];
- subjects[0] = "국어";
- subjects[1] = "영어";
- subjects[2] = "수학";
- int[] scores = new int[subjectCount];
- System.out.println(names[0] + "학생" + subjects[0] + "점수 : ");
- scores[0] = 100;
- System.out.println(scores[0]);
- System.out.println(names[0] + "학생" + subjects[1] + "점수 : ");
- scores[1] = 90;
- System.out.println(scores[1]);
- System.out.println(names[0] + "학생" + subjects[2] + "점수 : ");
- scores[2] = 80;
- System.out.println(scores[2]);
- int totalScore = scores[0] + scores[1] + scores[2];
- System.out.println("총점 : " + totalScore);
- double avg = totalScore / 3.0d;
- System.out.println("평점 : " + avg);
- String grade = null;
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Other";
- }
- System.out.println("등급 : " + grade);
- }
- }
728x90
반응형