public static void main(String[] args) throws NumberFormatException, IOException {
  
  
  // 국어, 영어, 수학 점수 입력 받아 총점, 평균 구하기(기초)
  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

  int kor,eng, math;
  
  do {
   System.out.print("국어 : ");
                   //NumberFormatException, IOException
   kor = Integer.parseInt(reader.readLine());


   if(kor <0 || kor>100) { // 입력을 받은 뒤에 if 조건문을 삽입하여 가이드 라인 제공
    System.out.println("점수는 0 ~ 100 범위 내에서 입력해주세요.");
   }


  }while(kor < 0 || kor > 100); // 조건식(다시 입력 받아야 하는 경우, 0~100 범위가 아닌 경우)
  
  do {
   System.out.print("영어 : ");
   eng = Integer.parseInt(reader.readLine());
  }while(eng < 0 || eng > 100);
  
  do {
   System.out.print("수학 : ");
    math = Integer.parseInt(reader.readLine());
  }while(math < 0 || math > 100);
  
  int total = kor + eng + math;
  float avg = total/3.0F;
  
  System.out.println("===== 기말고사 성적표 =====");
  System.out.println("국어\t 영어\t 수학\t 총점\t 평균");
  System.out.printf("%d\t %d\t %d\t %d\t %.2f", kor, eng, math, total, avg);


 }

+ Recent posts