Algorithm/etc

[코딩연습] 구구단 만들기

Anna-Jin 2021. 10. 14. 17:41
728x90
반응형

가장 간단하게 구구단을 코딩해보았다.

개념이 많이 부족한 것 같다.

 

 

내가 짠 코드
//구구단

public class Test {
	public static void main(String[] args) {

		for (int i = 2; i<10; i++) {
			System.out.println(String.format("%d단", i));
			for(int j=1; j<10; j++) {
				System.out.println(String.format("%d x %d = %d", i, j, i*j));
			}
		}
	}
}
출력값
2단
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18

...

9단
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81

 

728x90
반응형