문제

quiz

  • 3이상 9이하의 숫자를 입력받은 후 가로 10줄 세로10줄




코드

Shape.java

package pack_CusCls04;

import java.util.Scanner;

public class Shape {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		System.out.print("숫자를 입력하세요 : ");
		int num = scanner.nextInt();
		scanner.close();
		
		NumRectangle obj = new NumRectangle(num);
		obj.mtdRect();
	}

}

NumRectangle.java

package pack_CusCls04;

public class NumRectangle {
	
	private int num;

	public NumRectangle(int num) {
		this.num = num;
	}
	
	public void mtdRect() {
		
		System.out.println();
		
		int k = 1;
		
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j <10; j++) {
				System.out.print(" " + k++ + " ");
				if (k > num) {
					k= 1;
				}
			}
			System.out.println();
		}
		
	}

}


결과

quiz quiz

Leave a comment