관리 메뉴

nalaolla

배열예제 10 (점수관리 배열2) 본문

JAVA/4. Array

배열예제 10 (점수관리 배열2)

날아올라↗↗ 2016. 6. 22. 15:50
728x90
  1. package test.com;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7.  
  8. public class Test05score2 {
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.         // TODO Auto-generated method stub
  12.        
  13.         InputStream is = System.in;
  14.         InputStreamReader isr = new InputStreamReader(is);
  15.         BufferedReader br = new BufferedReader(isr);
  16.        
  17.         System.out.println("[성적처리 프로그램]");
  18.         //총인원 3명의 명단도 배열로 처리하시오.
  19.         //국,영,수 성적처리 프로그램을 작성하시오.
  20.         //과목과 점수는 배열을 사용하시오.
  21.         //출력은 반복문을 사용하시오.
  22.        
  23.        
  24.         int totalCount = 3;
  25.         String[] names = new String[totalCount];
  26.         names[0] = "KIM";
  27.         names[1] = "";
  28.         names[2] = "";
  29.        
  30.         int subjectCount = 3;
  31.         String[] subjects = new String[subjectCount];
  32.         subjects[0] = "국어";
  33.         subjects[1] = "영어";
  34.         subjects[2] = "수학";
  35.        
  36.         int[] scores = new int[subjectCount];
  37.        
  38.         System.out.println(names[0] + "학생" + subjects[0] + "점수 : ");
  39.         scores[0] = 100;
  40.         System.out.println(scores[0]);
  41.  
  42.         System.out.println(names[0] + "학생" + subjects[1] + "점수 : ");
  43.         scores[1] = 90;
  44.         System.out.println(scores[1]);
  45.        
  46.         System.out.println(names[0] + "학생" + subjects[2] + "점수 : ");
  47.         scores[2] = 80;
  48.         System.out.println(scores[2]);
  49.        
  50.         int totalScore = scores[0] + scores[1] + scores[2];
  51.         System.out.println("총점 : " + totalScore);
  52.         double avg = totalScore / 3.0d;
  53.         System.out.println("평점 : " + avg);
  54.        
  55.         String grade = null;
  56.         if (avg >= 90) {
  57.             grade = "A";
  58.         } else if(avg >= 80) {
  59.             grade = "B";
  60.         } else if(avg >= 70) {
  61.             grade = "C";
  62.         } else if(avg >= 60) {
  63.             grade = "D";
  64.         } else  {
  65.             grade = "Other";
  66.         }
  67.        
  68.         System.out.println("등급 : " + grade);
  69.     }
  70.  
  71. }


728x90

'JAVA > 4. Array' 카테고리의 다른 글

배열예제 12 (다중배열 2)  (0) 2016.06.22
배열예제 11 (다중배열)  (0) 2016.06.22
배열예제 9 (점수관리 배열)  (0) 2016.06.22
배열예제 8 (배열 대입)  (0) 2016.06.22
배열예제 7 (문자열 배열)  (0) 2016.06.22