본문 바로가기

JAVA

(별찍기) 왼쪽위가 직각인 삼각형

왼쪽 위가 90도인 직각삼각형

import java.util.Scanner; 
public class Ex02 { 
public static void main(String[]args) { 
Scanner scanner = new Scanner(System.in); 
System.out.println("====별찍기 2번===="); 
System.out.print("출력할 줄 수를 입력해주세요:"); 
int userNumber = scanner.nextInt(); 
for(int height = 1; height <= userNumber; height++) { 
String stars = ""; 
for(int width = userNumber ; width >= height; width--) { 
stars +="*"; 
} 
   
System.out.println(stars);  

} 


scanner.close(); 
} 
}









//-쌤방법






import java.util.Scanner; 
public class Ex0201 {  
public static void main(String[]args) { 
Scanner scanner = new Scanner(System.in); 
System.out.println("====별찍기 2번===="); 
System.out.print("출력할 줄 수를 입력해주세요:"); 
int userNumber = scanner.nextInt(); 
  
for(int height = 1; height <= userNumber; height++) { 
String stars = ""; 
for(int width = height; width <= userNumber; width++) { 
stars +="*"; 
} 
   
System.out.println(stars);  

} 


scanner.close(); 
} 
}