ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 클래스 문제
    과거⚰️ 2020. 12. 2. 17:18
    package day049;
    
    public class Day04903클래스문제1 {
    	public static void main(String[] args) {
    
    		Ex03 e = new Ex03();
    		
    		// 문제 1) 전체 합 출력
    		// 정답 1) 362
    		int total = 0;
    		for(int i=0; i<e.arr.length; i++) {
    			total = total + e.arr[i];
    		}
    		System.out.println(total);
    
    		// 문제 2) 4의 배수의 합 출력
    		// 정답 2) 264
    		total = 0;
    		for(int i=0; i<e.arr.length; i++) {
    			if(e.arr[i] % 4 == 0) {
    				total = total + e.arr[i];
    			}
    		}
    		System.out.println(total);
    
    		// 문제 3) 4의 배수의 개수 출력
    		// 정답 3) 3
    		int count = 0;
    		for(int i=0; i<e.arr.length; i++) {
    			if(e.arr[i] % 4 == 0) {
    				count = count + 1;
    			}
    		}
    		System.out.println(count);
    
    		// 문제 4) 짝수의 개수 출력
    		// 정답 4) 3
    		count = 0;
    		for(int i=0; i<e.arr.length; i++) {
    			if(e.arr[i] % 2 == 0) {
    				count = count + 1;
    			}
    		}
    		System.out.println(count);
    		
    	}
    }
    
    package day050;
    
    import java.util.Random;
    import java.util.Scanner;
    
    class Ex04 {
        int[] hakbuns = { 1001, 1002, 1003, 1004, 1005 };
        int[] scores = new int[5];
    }
    
    public class Day04904클래스문제2 {
        public static void main(String[] args) {
            Random ran = new Random();
            Scanner sc = new Scanner(System.in);
    
            Ex04 e = new Ex04();
            int size = e.hakbuns.length;
    
            // 문제1) scores배열에 1~100점 사이의 정수를 5개 저장
            // 예 1) 87, 11, 92, 14, 47
           for (int i=0; i<size; i++){
               e.scores[i] = ran.nextInt(100);
           }
    
            // 문제2) 전교생의 총점과 평균 출력
            // 예 2) 총점(251) 평균(50.2)
            int total = 0;
            int avg = 0;
            for (int i=0; i<size; i++){
                total += e.scores[i];
            }
            avg = total/5;
            System.out.println("총 " + total + "평균 " + avg);
            // 문제3) 성적이 60점 이상이면 합격. 합격생 수 출력
            // 예 3) 2명
            int cnt = 0;
            for (int i=0; i<size; i++){
                if(e.scores[i]>=60){
                    cnt++;
                }
            }
            System.out.println(cnt+"명");
            // 문제4) 인덱스를 입력받아 성적 출력
            // 정답4) 인덱스 입력 : 1 성적 : 11점
            System.out.println("index : ");
            int in = sc.nextInt();
            System.out.println(e.scores[in]);
            // 문제5) 성적을 입력받아 인덱스 출력
            // 정답5) 성적 입력 : 11 인덱스 : 1
            System.out.println("score : ");
            int score =sc.nextInt();
            for (int i=0; i<size; i++){
                if(score==e.scores[i]){
                    System.out.println(i);
                }
            }
            // 문제6) 학번을 입력받아 성적 출력
            // 정답6) 학번 입력 : 1003 성적 : 45점
            System.out.println("num : ");
            int num =sc.nextInt();
            for (int i=0; i<size; i++){
                if(num==e.hakbuns[i]){
                    System.out.println(e.scores[i]);
                }
            }
            // 문제7) 학번을 입력받아 성적 출력
            // 단, 없는학번 입력 시 예외처리
            // 예 7)
            // 학번 입력 : 1002 성적 : 11점
            // 학번 입력 : 1000 해당학번은 존재하지 않습니다.
            System.out.println("학번 입력");
            num = sc.nextInt();
            cnt = 0;
            int index = 0;
            for (int i=0; i<size; i++){
                if(num==e.hakbuns[i]){
                    cnt++;
                  index = i;
                }
            }
            if(cnt==0){
                System.out.println("없는 학번");
            }else {
                System.out.println(e.scores[index]);
            }
            // 문제8) 1등학생의 학번과 성적 출력
            // 정답8) 1004번(98점)
            int one = 0;
            int oneNum = 0;
            for (int i=0; i<size; i++){
                if(one<=e.scores[i]){
                    one = e.scores[i];
                    oneNum =i;
                }
            }
            System.out.println("1등:"+one +" "+e.scores[oneNum]+"점");
        }
    }
    
    package day050;
    
    import java.util.Scanner;
    
    class Ex05 {
        String name = "";
    
        int[] arHakbun = {1001, 1002, 1003, 1004, 1005};
        int[] arScore  = {  92,   38,   87,  100,   11};
    }
    
    public class Day04905클래스문제3 {
        public static void main(String[] args) {
    
            Scanner scan = new Scanner(System.in);
    
            Ex05 e = new Ex05();
            e.name = "Green";
    
            while(true) {
                System.out.println("=== " + e.name + "===");
                System.out.println("1.전교생 성적확인");
                System.out.println("2.1등학생 성적확인");
                System.out.println("3.꼴등학생 성적확인");
                System.out.println("4.성적확인하기");		// 학번 입력받아서 성적확인
                System.out.println("5.종료하기");
    
                int choice = scan.nextInt();
                if(choice == 1) {}
                else if(choice == 2) {}
                else if(choice == 3) {}
                else if(choice == 4) {}
                else if(choice == 5) {
                    break;
                }
    
            }
    
        }
    }
    
    
    
    
Designed by Tistory.