본문 바로가기

Algorithm/Beginner Coder

Jungol (Java) - 1291 : 구구단

www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=574&sca=20

 

JUNGOL

 

www.jungol.co.kr

 

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s, e;

        while (true) {
            s = sc.nextInt();
            e = sc.nextInt();
            if (s > 1 && s < 10 && e > 1 && e < 10) {
                break;
            } else {
                System.out.println("INPUT ERROR!");
            }
        }

        if (s < e) {
            for (int i = 1; i < 10; i++) {
                for (int j = s; j <= e; j++) {
                    System.out.print(j + " * " + i + " = ");
                    System.out.printf("%2d", j * i);
                    System.out.print("   ");
                }
                System.out.println();
            }
        } else {
            for (int i = 1; i < 10; i++) {
                for (int j = s; j >= e; j--) {
                    System.out.print(j + " * " + i + " = ");
                    System.out.printf("%2d", j * i);
                    System.out.print("   ");
                }
                System.out.println();
            }
        }
    }
}