이번에는 역 직각삼각형을 만들어 볼 차례이다.
나 혼자 고민을 하다가 해결이 되지 않아 인터넷에 검색을 한 이후에 만들어 보았다.
import java.util.Scanner;
public class star0421 {
public class star0421 {
public static void main(String[] args) {
int i,j;
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
for(i=1;i<num;i++) {
for(j=num;j>0;j--) {
if(i<j) {
System.out.print(" ");
}
else System.out.print("*");
}
System.out.println("");
}
scan.close();
int i,j;
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
for(i=1;i<num;i++) {
for(j=num;j>0;j--) {
if(i<j) {
System.out.print(" ");
}
else System.out.print("*");
}
System.out.println("");
}
scan.close();
}
}
빨간 부분을 공백으로 하지 않고 ("")라고 표기하면 정상적인 모양의 직각삼각형이 나온다.
결과는
9
*
**
***
****
*****
******
*******
********
if문, else문을 이용하여 역삼각형을 만들면 된다.
'프로그래밍 > JAVA' 카테고리의 다른 글
Mac Big Sur 업데이트 이후 sts 눌렀는데 failed to create the Java Virtual Machine 될 때 (0) | 2020.12.14 |
---|---|
Generic (0) | 2018.10.19 |
컬렉션 Collection (0) | 2018.10.19 |
자바 다이아몬드 만들기 (0) | 2018.04.20 |
자바 직각삼각형 만들기(1) (0) | 2018.04.20 |