71. 콘솔에서 정수 한개가 입력되었을때 카운트다운을 출력하라

입력 범위 : 1 ~ 100

입력 예시

5

출력 예시

5

4

3

2

1

JAVA

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int maxCount = scan.nextInt();
        scan.close();
		while(maxCount > 0) {
			System.out.println(maxCount--);
		}
	}
}

Swift 4.2

import Foundation

let line = readLine();
if line != nil,var maxCount = Int(line!) {
    while maxCount > 0 {
        print(maxCount)
        maxCount-=1
    }
}

 

JAVA쪽에 print와 감소를 같이 해줬는데

버전 별로 의도대로 안될수도 있습니다.

그냥 밑의 스위프트 처럼 출력과 감소를 줄을 나누는게 더 나을수도 있어요.

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

+ Recent posts