[Java] 백준 - 별 찍기-16
백준 - 별 찍기 -16
백준 Java
링크: https://www.acmicpc.net/problem/10991
문제
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
입력
첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.
출력
첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다.
예제 입력 1
2
예제 출력 1
*
* *
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 1; i <= n; i++) {
for(int j = n-i; j > 0; j--)
System.out.print(" ");
System.out.print("*");
for(int j = 1; j < i; j++)
System.out.print(" *");
System.out.println();
}
}
}
Leave a comment