본문 바로가기

Algorithm/Beginner Coder

Jungol (Java) - 1341 : 구구단2

www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2076&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 = s; i <= e; i++) {
                for (int j = 1; j < 10; j++) {
                    System.out.print(i + " * " + j + " = ");
                    System.out.printf("%2d", i * j);
                    System.out.print("   ");
                    if (j % 3 == 0) {
                        System.out.println();
                    }
                }
                System.out.println();
            }
        } else {
            for (int i = s; i >= e; i--) {
                for (int j = 1; j < 10; j++) {
                    System.out.print(i + " * " + j + " = ");
                    System.out.printf("%2d", i * j);
                    System.out.print("   ");
                    if (j % 3 == 0) {
                        System.out.println();
                    }
                }
                System.out.println();
            }
        }
    }
}