Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 25, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/1a657f77258299477ad8e76e36acfc72 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/1a657f77258299477ad8e76e36acfc72 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-2
import java.util.Random;
import java.util.Scanner;
public class En4_2 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
Random rand = new Random();
// 乱数0~89を作り、それに+10する。
int no = rand.nextInt(90) + 10;
int x;
do {
System.out.print("いくつかな?:");
x = stdIn.nextInt();
if (x > no) {
System.out.println("もっと小さい数だよ");
} else if (x < no) {
System.out.println("もっと大きい数だよ");
}
} while (x != no);//xがnoとなるまで繰り返す。
System.out.println("正解です。");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment