달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

구구단 찍기

Java 기초부터 2019. 3. 18. 11:47

* 기본 구구단 찍기

1
2
3
4
5
6
7
8
9
10
public class Gugudan {
    public static void main(String[] args) {
        for(int i=2; i<=9; i++) {
            for(int k=1; k<=9; k++) {
                System.out.printf("%d*%d = %d%n", i, k, i*k);
            }
        }
    }
}
 
cs



* 출력하고 싶은 단만 찍기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Scanner;
 
public class Gugudan {
    public static void main(String[] args) {
        int num;
        System.out.print("출력하고 싶은 구구단 수를 입력하세요.>");
        Scanner sc = new Scanner(System.in);
        num = sc.nextInt();
        sc.close();
        
        for(int i=num; i<=num; i++) {
            for(int k=1; k<=9; k++) {
                System.out.printf("%d*%d = %d%n", i, k, i*k);
            }
        }
    }
}
 
cs



* 구구단 3단 출력 중 4의 배수 제외하고 찍기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Gugudan{
    public static void main(String[] args){
        
        for(int i =3; i<=3; i++){
            for(int k=1; k<=9; k++){
                if(k == 4){
                     System.out.print("");
                }
                 else {
                        System.out.printf("%d * %d = %d%n", i, k, i*k);
                }
            }
        }
    }
cs





정말 아주 가~끔 SI업체 기술면접볼 때 구구단 찍기 손코딩을 시키는 곳이 있다.

'Java 기초부터' 카테고리의 다른 글

객체지향 프로그래밍  (0) 2019.03.26
여러가지 모양의 별 찍기  (0) 2019.03.26
Scanner를 이용한 별찍기  (0) 2019.03.18
for문 기초 문법  (0) 2019.03.18
자바로 프로그램 작성하기  (0) 2019.03.09
Posted by 새벽네시반
|