Study 각 학생들의 점수를 입력받아 평균과 전체평균 구하기 (클래스변수 사용) bslime 2008. 5. 31. 01:11 import java.io.*; class Student { double avg; static double avg_tt; static int count; Student(double sc1, double sc2, double sc3) { avg = (sc1+sc2+sc3) / 3.0; avg_tt += avg; count++; } static double avg() { double avg_all = avg_tt/count; return avg_all; } } class Main { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("입력받기 원하는 학생의 수를 입력하시오"); int stus = Integer.parseInt(in.readLine()); Student value[] = new Student[stus]; for(int i=0; i<stus; i++) { System.out.println((i+1) + "번째 학생의 점수를 입력하시오"); System.out.print("1번째 과목의 점수 : "); double sc1 = Double.parseDouble(in.readLine()); System.out.print("2번째 과목의 점수 : "); double sc2 = Double.parseDouble(in.readLine()); System.out.print("3번째 과목의 점수 : "); double sc3 = Double.parseDouble(in.readLine()); value[i] = new Student(sc1, sc2, sc3); } System.out.println(); for(int i=0; i<stus; i++) { System.out.println((i+1) + "번째 학생의 평균점수는 : " + value[i].avg); } System.out.println("총 " + Student.count + "명의 학생의 점수가 입력되었고 학생들의 평균은 : " + Student.avg()); } }