본문 바로가기

JAVA

(별찍기) 역 정삼각형

import java.util.Scanner; 
public class Ex06 { 
public static void main(String[]args) { 
Scanner scanner = new Scanner(System.in); 
System.out.println("====별찍기 6번====");  
System.out.print("출력할 줄 수를 입력해주세요:"); 
int userNumber = scanner.nextInt(); 

for(int height = userNumber; height >= 1; height--) { 
String stars = ""; 
for(int width = 1; width <= userNumber-height; width++) { 
stars += " "; 
} 
for(int width = 1; width <= 2*height-1; width++) { 
stars += "*"; 
} 
System.out.println(stars); 
} 

scanner.close(); 
}  
}