본문 바로가기

Algorithm/CodeUp

[CodeUp_Java] Q1351 : 구구단 출력하기 2

반응형

안녕하세요! Plitche(플리체)입니다.
이번 포스팅의 주제는 Q1351 : 구구단 출력하기 2 (자바, JAVA)입니다.

Intro

Question

문제 설명

입력

시작 단과 마지막 단을 입력한다.(정수1~9)

출력

예시처럼 구구단을 출력한다.

예시

  • 입력 : 5 6
  • 출력 :
    51=5
    5
    2=10
    53=15
    5
    4=20
    55=25
    5
    6=30
    57=35
    5
    8=40
    59=45
    6
    1=6
    62=12
    6
    3=18
    64=24
    6
    5=30
    66=36
    6
    7=42
    68=48
    6
    9=54

Solution (풀이)

  • 풀이 : 메모리 11124, 시간 67
public class Answer1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        StringBuilder sb = new StringBuilder();

        int start = Integer.parseInt(st.nextToken());
        int end = Integer.parseInt(st.nextToken());

        for(int i=start; i<=end; i++) {    // 시작 단과 끝 단을 지정
            for(int j=1; j<=9; j++) {    // 구구단 시작
                sb.append(i).append("*").append(j).append("=").append(i*j).append("\n");
            }
        }

        System.out.println(sb);
        br.close();
    }
}

Ranking(순위)

반응형