1. 구구단

package ex03;

public class GugudanEx01 {
    public static void main(String[] args) {
        //2~9단까지 출력되는 프로그램

        for (int x = 1; x < 10; x++)
        {
            for (int i = 2; i < 10; i++) {
                System.out.print(i + " * " + x +" = " + x * i + "\\t");
            }
            System.out.println();
        }
    }
}

Untitled

//스캐너를 이용하여 입력받은 단만 출력.
package ex03;

import java.util.Scanner;

public class GugudanEx02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int user;
        System.out.print("1~9사이의 숫자를 입력: ");
        user = sc.nextInt();

        System.out.println(user + "단만 출력");

        for (int i = 1; i < 10; i++) {
            System.out.println(user + " * " + i + " = " + user * i);
        }
    }
}

Untitled

2. 숫자 추측 게임

package ex03.MiniProject;

import java.util.Scanner;

public class NumberGuessingGame {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int computer = (int) (Math.random() * 100);

        int a = 0;
        while (true)
        {
            System.out.print("정답을 추측하여 보시오: ");
            int user = sc.nextInt();
            if (computer == user) {
                a++;
                System.out.println("축하합니다. " + "시도횟수 = " + a);
                break;
            } else if (computer > user) {
                a++;
                System.out.println("제시한 정수가 컴퓨터의 정수보다 낮습니다.");
            } else {
                a++;
                System.out.println("제시한 정수가 컴퓨터의 정수보다 높습니다.");
            }
        }
    }
}

Untitled