使用Java(for循环,if判断语句)编写竞猜价格游戏

您所在的位置:网站首页 竞猜商品价格 使用Java(for循环,if判断语句)编写竞猜价格游戏

使用Java(for循环,if判断语句)编写竞猜价格游戏

2024-07-16 21:42| 来源: 网络整理| 查看: 265

【练习】猜商品价格游戏

1次猜中:奖励华为Mate X 手机一部;2-3次猜中:奖励 switch 游戏机一部;5次以内猜中:小米运动手环一个;

代码如下:

package java学习代码文件;

import java.util.Scanner;

public class caispjiage {     public static void main(String[] args) {         //final int price = (((int)(Math.random()*1000))%9+1)*1000;//竞猜答案为1000~9000中随机一个整千的数值         //System.out.println(price);         final int price = 5000;         int guessPrice = -1;         int count = 0;         String prizeName = null;                  for(int i=0;i=2&&count == 3){                     System.out.println("恭喜您,获得二等奖:swith游戏机一部");                                      }else {                     System.out.println("恭喜您,获得三等奖:小米运动手环一个");                                      }                 break;             }              //        else{              //        System.out.println("猜错了,很遗憾!");              //        }             else if(guessPrice > price){                 System.out.println("猜大了,请继续");             }else if(guessPrice < price){                 System.err.println("猜小了,请继续");             }         }     } }  

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3