다른풀이 (for문 사용)
public class Mission01 {
//총점을 구현후 리턴하는 메소드
public static int getSum(int kor,int eng, int mat) {
int total = kor + eng + mat;
return total;
}
//평균을 구하고 리턴하는 메소드
public static int getAvg(int total) {
int avg = total / 3;
return avg;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int kor,eng,mat,sum;
int avg;
System.out.print("국어 입력 : ");
kor = Integer.parseInt(sc.nextLine());
System.out.print("영어 입력 : ");
eng = Integer.parseInt(sc.nextLine());
System.out.print("수학 입력 : ");
mat = Integer.parseInt(sc.nextLine());
System.out.println("이름 입력 : ");
String name = sc.nextLine();
//sum = kor + eng + mat;
sum = getSum(kor, eng, mat);
//avg = sum / 3;
avg = getAvg(getSum(kor, eng, mat));
DecimalFormat form = new DecimalFormat("##.##");
System.out.println("이름 : "+ name);
System.out.println("국어 : "+ kor);
System.out.println("영어 : "+ eng);
System.out.println("수학 : "+ mat);
System.out.println("총점 : "+ sum);
System.out.println("평균 : "+ avg);
System.out.println("평균 : "+ form.format(avg));
String grade = "";
switch (avg/10) {
case 10:
case 9:
grade = "A학점";
break;
case 8:
grade = "B학점";
break;
case 7:
grade = "C학점";
break;
case 6:
grade = "D학점";
break;
default:
grade = "F학점";
break;
}
System.out.println("학점 : " +grade);
}
}