본문 바로가기
웹프로그래밍 무작정따라하기/JAVA_Spring

[JAVA] 구구단 세로출력

by RIMD 2021. 2. 18.

구구단 출력

for(int i = 2; i <= 9; i++) {
  for(int j = 1; j <= 9; j++) {
  	System.out.println(i + "*" + j + "=" + i*j);
  }
}

.

.

.

9단까지 가로로 출력됨

 


 

구구단 세로 출력

살짝 비꼰 문제라고 볼 수 있음

 

이스케이프 시퀀스

이스케이시퀀스 의미
\t 공백
\n 줄바꿈

 

for(int i = 2; i <= 9; i++) {
  for(int j = 1; j <= 9; j++) {
  	// 세로로 1*2 = 2   2*2 = 4  3*2 = 6  .... 출력
    // "\t" 공백 넣기 하지않으면 깔끔하게 정렬되지 않는다는 점 유의!
    System.out.print(j + "*" + i + "=" + i*j + "\t");
  }
  	// 줄바꿈
  	System.out.println("");
}

 

댓글