728x90
삼성 SW Expert Academy
문제 1545. 거꾸로 출력해 보아요
링크

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=1&contestProbId=AV2gbY0qAAQBBAS0&categoryId=AV2gbY0qAAQBBAS0&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=JAVA&select-1=1&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

조건

주어진 숫자부터 0까지 순서대로 출력하라

입력

8

출력

8 7 6 5 4 3 2 1 0

예상분석

입력값부터 -1씩 연산하여 출력하는 반복문을 0이 될때까지 실행한다.

코드
import java.util.Scanner;

class Solution
{
    public static void main(String args[]) throws Exception {

        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();

        while (T >= 0) {
            System.out.print(T-- + " ");
        }

        sc.close();
    }
}
728x90

+ Recent posts