ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 사전 과제
    멋사 부트캠프/과제 2025. 2. 27. 00:02

     

    import java.util.Scanner;

    public class hello {
        public static void main(String[] args) throws Exception {
            Ex3 ex = new Ex3();
           
            System.out.println("Hello, World!");

        }

        static class Ex1_1 {
            double kor[] = {10, 20, 87, 85.5, 80, 90, 35.2, 85, 70, 90};        //1차원 배열에 초기값을 미리 설정
            int cnt = 0;
            double tot = 0;
            double ave = 0;
           
            Ex1_1(){  
                for(int i=0; i<10; i++){
                    if(this.kor[i] >= 80){
                        this.tot += this.kor[i];
                        this.cnt++;
                        this.ave += this.kor[i];
                        this.ave /= this.cnt;
                    }
                }
                this.tot = (int)this.tot;
                this.ave = (int)this.ave;
            }
            void printInfo(){
                System.out.println("80점 이상 학생 수 : " + this.cnt);
                System.out.println("80점 이상 학생 평균 : " + this.ave);
                System.out.println("80점 이상 학생 총점 : " + this.tot);
            }
        }
       
        static class Ex1_2 {
            double A[][] = {                                                   //1차원 배열에 초기값을 미리 설정
                {90, 80, 72},
                {81, 72.5, 85.5},
                {72, 85, 30.5},
                {60, 80, 90},
                {90, 90, 100},
                {82, 62, 50},
                {70, 50, 50},
                {60, 60, 35},
                {70, 60, 35},
                {90, 82.5, 35.5}
            };
            int cnt = 0;
            double tot = 0, ave = 0;
            double ktot = 0, htot = 0, mtot = 0;
           
            Ex1_2(){
                for(int i=0; i < 10; i++){                                     //학생 행 선택
                    for(int j=0; j < 3; j++){                                  //과목 열 선택
                        this.tot += this.A[i][j];
                        if(j == 0){
                            ktot += this.A[i][j];
                        }
                        if(j == 1){
                            htot += this.A[i][j];
                        }
                        if(j == 2){
                            mtot += this.A[i][j];
                        }
                    }
                    this.ave = tot / 3;
                    if(this.ave >= 80){
                        this.cnt++;
                    }
                    this.tot=0;
                    this.ave=0;
                }
                System.out.println("3과목 평균 80 이상 학생 수 : " + this.cnt);
                System.out.println("국어 총점 : " + this.ktot);
                System.out.println("국사 총점 : " + this.htot);
                System.out.println("수학 총점 : " + this.mtot);
            }
        }

        static class Ex2 {
            int A[] = {9, 15, 10, 7, 6, 30, 21};
            int n3 = 0;
            int sum = 0;

            Ex2(){
                for(int i=0; i<7; i++){
                    this.n3 = this.A[i] % 3;
                    if(this.n3 == 0){
                        this.sum += this.A[i];
                    }
                }
                System.out.println("3의 배수의 합 : " + this.sum);
            }
        }

        static class Ex3 {
            double A = 0, M = 0, n4 = 0;

            Ex3(){
                Scanner scan = new Scanner(System.in);
                System.out.print("자연수를 입력하세요 : ");
                this.A = scan.nextInt();

                M = A / 4;
                n4 = A % 4;

                System.out.println((int)(this.M + this.n4));

                scan.close();
            }        
        }

        static class Ex4 {
           
           
        }

        static class Ex5 {
           
        }

        static class Ex6 {
           
        }
       
        static class Ex7 {
           
        }
    }

    '멋사 부트캠프 > 과제' 카테고리의 다른 글

    workshop01  (0) 2025.03.05
Designed by Tistory.