본문 바로가기

프로그래밍/자바

[자바] 정올 541 ~ 548 : 반복제어문2 - 자가진단 1 ~ 8

728x90
반응형
SMALL

자가진단1

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        System.out.println(a.repeat(20));
    }
}

자가진단2

public class Main {
    public static void main(String[] args) {
        for(int i = 10; i <=20; i++) System.out.print(i + " ");
    }
}

자가진단3

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        for(int i = 1; i <= a; i++) if(i%2 == 0) System.out.print(i + " ");
    }
}

자가진단4

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int sum = 0;
        for(int i = a; i<=100;i++) sum += i;
        System.out.println(sum);
    }
}

자가진단5

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i, m3 = 0, m5= 0;
        for(int a = 0; a < 10; a++){
            i=sc.nextInt();
            if(i%3 == 0) m3++;
            if(i%5 == 0) m5++;
        }//end for
        System.out.println("Multiples of 3 : " + m3);
        System.out.println("Multiples of 5 : " + m5);

    }
}

자가진단6

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double sum = 0;
        int n = sc.nextInt();
        for(int i = 0; i < n; i++) sum += sc.nextInt();
        System.out.printf("avg : %.1f\n", sum/n);
        if(sum/n >= 80) System.out.println("pass");
        else System.out.println("fail");
    }
}

자가진단7

public class Main {
    public static void main(String[] args) {
        for (int i = 2; i <= 6; i++) {
            for(int j = 0; j < 5; j++){
                System.out.print((i+j) + " ");
            }
            System.out.println();
        }
    }
}

자가진단8

 

public class Main {
    public static void main(String[] args) {
        for(int i =2; i <= 4; i++){
            for(int j = 1; j <= 5; j++){
                System.out.printf("%-2d*%2d =%3d   ", i,j,i*j);
            }
            System.out.println();
        }
    }
}
728x90
반응형
LIST