[백준 브론즈 Ⅴ] 2739번: 구구단

DONI·2021년 8월 7일
0

Baekjoon Online Judge

목록 보기
19/31
post-thumbnail

문제

N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다.


입력

첫째 줄에 N이 주어진다. N은 1보다 크거나 같고, 9보다 작거나 같다.


출력

출력형식과 같게 N1부터 N9까지 출력한다.


예제 입력 1

2

예제 출력 1


소스코드

  • Java 첫 번째 방법 : for 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		for (int i = 0; i < 9; i++)
			System.out.println(n + " * " + (i + 1) + " = " + n * (i + 1));
	}
}
  • Java 두 번째 방법 : while 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int i = 0;
		while (i < 9) {
			System.out.println(n + " * " + (i + 1) + " = " + n * (i + 1));
			i++;
		}
	}
}
  • Java 세 번째 방법 : do-while 문
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int i = 0;
		do {
			System.out.println(n + " * " + (i + 1) + " = " + n * (i + 1));
			i++;
		} while (i < 9);
	}
}

[바로가기] 2739번: 구구단

profile
틀린 내용이 있다면 댓글 또는 이메일로 알려주세요 ❤ꔛ❜

0개의 댓글