Last active
October 25, 2016 12:21
-
-
Save mokomokohitsuzi/1a657f77258299477ad8e76e36acfc72 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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