import java.util.Scanner;
/**
*
* 猜数字游戏(5次)
* @author Monster丶ZF
* @version1.8
* @data 2019年4月8日
* @remakeTODO
*/
public class GuessDemo {
public static void main(String[] args) {
// 用户要猜的数字
// 用户猜的次数
//final int price = (int)(Math.random()*10000)%8001+1000;
//常量[1000-9000]包括1001、1002.....8999
final int price = ((int)(Math.random()*10000) % 9 + 1 )* 1000;
// 常量1000-9000指的是1000、2000、3000....9000
//乘1000之前是[1-9],乘完就1000-9000],就不包括中间的1001、1560类似的数字
//System.out.println(price);
int guessPrice = -1; // 用户猜测的单价
int count = 0; //用户猜的总次数
String prizeName = null ;
for (int i = 0; i < 5; i++) {
System.out.println("请输入神秘商品的单价:(" + ++count + "次)");
guessPrice = new Scanner(System.in).nextInt();
if(guessPrice == price){ //在猜测正确的情况下,在判断猜测的次数看奖品
if(count == 1){
System.out.println("牛逼了,一次就猜对了");
//System.out.println("奖品:iphone8s plus plus 土豪金");
prizeName = "iphone8s plus plus 土豪金";
}else if(count >= 2 && count <= 3 ){
//System.out.println("奖品:华为荣耀手环Zero");
prizeName = "华为荣耀手环Zero";
}else {
//System.out.println("奖品:小米蓝牙耳机青春版");
prizeName = "小米蓝牙耳机青春版" ;
}
break; //如果5次内中奖了 跳出循环
}else if(guessPrice < price ) {
if(count == 1){
System.out.println("小了喔,不要灰心,游戏才刚刚开始!");
}else if(count >= 2 && count <= 3 ){
System.out.println("还是小了喔,在大点!");
}else if(count == 4) {
System.out.println("还是小,在大!");
}
}else if(guessPrice > price ){
if(count == 1){
System.out.println("大了喔,不要灰心,游戏才刚刚开始!");
}else if(count >= 2 && count <= 3 ){
System.out.println("还是大了喔,在小点!");
}else if(count == 4) {
System.out.println("还是大,在小!");
}
}
}
if(null == prizeName){
System.out.println("很遗憾,五次机会用完了,期待下次吧!");
}else{
System.out.println("恭喜,您中奖了,奖品是:");
System.out.println(prizeName);
}
}
}
猜数字游戏!!
最新推荐文章于 2019-10-30 17:43:24 发布