본문 바로가기
알고리즘/백준

[Java] for문 - 기찍N (2742번)

by 자연송어 2021. 6. 20.

'N찍기' 를 반대로 수행해야 되서 이름까지 반대로 '기찍N' 인 문제

해결과정 🤷‍♂️

package forStatement;
import java.util.Scanner;

public class shootAStar1 {

	public static void main(String[] args) {
		Scanner my = new Scanner(System.in);
		int a;
		a = my.nextInt();
		
		for(int i = a; 0 < a; i--)
		System.out.println(i);
	}
}
더보기

결과값

-로 무한루프

 

정답 🙆‍♂️

 

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner my = new Scanner(System.in);
		int a;
		a = my.nextInt(); //a 입력값 받기 위한 객체
		
		for(int i = a; i > 0; i--) //i가 a부터 작아지고 0까지 출력하도록 조절
		System.out.println(i); //i를 출력
	}
}

'알고리즘 > 백준' 카테고리의 다른 글

[백준] 2753번 : 윤년 (JAVA-자바)  (0) 2021.07.23
[Java] for문 - 별찍기-1 (2438번)  (0) 2021.06.20
[Java] for문 - N찍기 (2741번)  (0) 2021.06.20
[Java] for문 - 구구단 - 2739번  (0) 2021.06.20