본문 바로가기

프로그래밍/자바

[자바] 정올 130 ~ 139 : 반복제어문2 - 형성평가1 ~ 10

728x90
반응형
SMALL

형성평가1


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 = 0; i < a; i++) System.out.println("JUNGOL");
    }
}

형성평가2

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        int min = a < b ? a : b;
        int max = a > b ? a : b;
        for(int i = min; i <= max; 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(), sum = 0;

        for(int i = 1; i <= a; i++)if(i%5 == 0) sum += i;
        System.out.println(sum);
    }

}

형성평가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 = 0; i < a; i++) sum += sc.nextInt();
        double avg = (double)sum/a;
        System.out.printf("%.2f", avg);
    }
}

형성평가5

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

형성평가6

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), count = 0;
        double sum = 0.0;
        int min = a < b ? a : b;
        int max = a > b ? a : b;
        for(int i = min; i<= max; i++){
            if(i%3 == 0 || i%5 == 0){
                sum += i;
                count++;
            }
        }
        System.out.println("sum : " + (int)sum);
        System.out.printf("avg : %.1f",sum/count);
    }
}

형성평가7

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 <= 10; i++) System.out.print((i*a) + " ");
    }
}

형성평가8

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();

        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= b; j++) {
                System.out.print((i*j) + " ");
            }
            System.out.println();
        }
    }
}

형성평가9

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++){
            for(int j = 1; j <= a; j++){
                System.out.printf("(%d, %d) ", i, j);
            }
            System.out.println();
        }
    }
}

형성평가10

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();

        if(a>b){
            for(int j = 1; j < 10; j++){
                for (int i = a; i >= b; i--){
                    System.out.printf("%d * %d =%3d   ", i, j, i*j);
                }
                System.out.println();
            }
        }
        else{
            for(int j = 1; j < 10; j++){
                for (int i = a; i <= b; i++){
                    System.out.printf("%d * %d =%3d   ", i, j, i*j);
                }
                System.out.println();
            }

        }

    }
}
728x90
반응형
LIST