85. 콘솔에서 정수 한 개를 입력받고, 1부터 입력 받은 수 까지 출력하라. 단, 3의 배수는 출력하지 않는다.

입력 범위 : 1 ~ 100

입력 예시

10

출력 예시

1 2 4 5 7 8 10

JAVA

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int endNum = scan.nextInt();
		scan.close();
		for (int i = 1; i <= endNum; i++) {
			if(i%3==0) continue;
			System.out.print(i + " ");
		}
	}
}

Swift 4.2

import Foundation

if let line = readLine(),let endNum = Int(line) {
    for i in 1...endNum {
        if i % 3 == 0 {
            continue
        }
        print(i, separator: "", terminator: " ")
    }
}

이번에는 continue를 써보세요 라는 문제였습니다.

https://codeup.kr/problem.php?id=1088

 

 

+ Recent posts