IT/Programming / / 2023. 4. 25. 15:32

[JAVA] 구구단 게임 예제

반응형
package dayday4;

import java.util.Scanner;

public class QUIZ01 {
	public static void main(String[] args) {
		int rand1 = (int) (Math.random() * 9) + 1;
		int rand2 = (int) (Math.random() * 9) + 1;
		int result = 0;
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		System.out.println("구구단 게임입니다  정답을 입력하세요");
		System.out.println(rand1 + "x" + rand2 + "=" + "?");

		result = sc.nextInt();// input a integer type

		String m = (result == rand1 * rand2) ? "정답입니다." : "땡입니다.";
		System.out.println(m);
	}
}
반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유