TIME IN THE SUBWAY :GUESS NUM !
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TIME IN THE SUBWAY :GUESS NUM !相关的知识,希望对你有一定的参考价值。
import java.util.Random;
import java.util.Scanner;
public class GuessNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Hello,MZ. WLCOME HERE! ^_^");
System.out.print("Press 1 to Start. ");
System.out.println("Press 2 to Quit.Please: ");
while (true) {
int button = sc.nextInt();
switch (button) {
case 1:
// 产生随机数,答案
Random r = new Random();
int answer = r.nextInt(100) + 1;
System.out.println("Start Now!");
for (int i = 1; i <= 10; i++) {
// 输入键盘录入数字
System.out.println("==");
System.out.println("Please enter your number:");
int enterNum = sc.nextInt();
// 判断大小
if (enterNum > answer) {
if (i < 10) {
System.out.println("你猜大了,往小了猜试试?");
System.out.println("你还有" + (10 - i) + "次机会。加油!");
} else {
System.out.println("很遗憾,你没有机会了!");
System.out.println("再来一局?");
System.out.println("Press 1 to Try. ");
System.out.println("Press 2 to Quit.");
}
} else if (enterNum < answer) {
if (i < 10) {
System.out.println("你猜小了,往大了猜试试?");
System.out.println("你还有" + (10 - i) + "次机会。加油!");
} else {
System.out.println("很遗憾,你没有机会了!");
System.out.println("再来一局?");
System.out.println("Press 1 to Try Again.");
System.out.println("Press 2 to Quit.");
}
} else {
System.out.println("恭喜你,猜对啦!");
System.out.println("再来一局?");
System.out.println("Press 1 to Try Again.");
System.out.println("Press 2 to Quit.");
break;
}
}
break;
case 2:
System.out.println("Game Over!");
break;
default:
System.out.println("Are u kidding?");
break;
}
}
}
}
以上是关于TIME IN THE SUBWAY :GUESS NUM !的主要内容,如果未能解决你的问题,请参考以下文章
(HDU)1562-- Guess the number (猜数字)