import java.util.Scanner;
import java.util.Random;
class CaiQuan
{
public static void main(String[] args)
{
//创建对象
Scanner sc = new Scanner(System.in);
Random ran = new Random();
System.out.println("欢迎来到魔鬼赌城,在这里度过美好的时光");
//调用对象方法
int suiJi = ran.nextInt(100)+1;
int count=0;
while(true)
{
int num = sc.nextInt();
//定义变量,用来记录输入的次数.
if (num<0&&num>100)
{
System.out.println("游戏里没有你输入的点数,请重新输入");
}
else if (num<suiJi)
{
count++;
System.out.println("第"+count+"次,你输入的数字点数小了,你输了,");
}
else if (num>suiJi)
{
count++;
System.out.println("第"+count+"次,你输入的数字点数大了,你输了,");
}
else
{
count++;
System.out.println("恭喜你第"+count+"次你猜对了点数你赢了");
break;
}
if(count==5)
{
System.out.println("你输入的次数到了五次,请继续投币 重新开始");
break;
}
}
System.out.println("这才是可以赢钱的点数:"+suiJi);
}
}
|
|