study/퀴즈
[자바/java] 구구단 3단씩 출력
김람보
2021. 10. 12. 09:35
3중 for문을 이용하여 출력
public class Gugudan_3 {
public static void main(String[] args) {
for(int i=2;i<10;i+=3){// 3 단씩 출력되기 때문에 한 줄이 넘어갈 때 +3
for(int j=0;j<10;j++){
for(int k=0;k<3;k++){// 한 줄에 3개의 단이 출력 됨
if(j==0) System.out.printf("%d단", i+k);// 몇 단인지 출력해주기 위한 조건
else System.out.printf("%2d * %d = %2d ", i+k, j, (i+k)*j);
}
System.out.println();
}
}
}
}