小白基础的猜数游戏
电脑随机给出1~100之间的数
玩家进行猜数
电脑会给与 “偏大,偏小“的提示;
代码其中就Math.random()是随机函数
number是电脑给的数
Scanner in= new Scanner(System.in);
int number=(int)(Math.random()*100+1);
int a;
int count=0;
do{
a=in.nextInt();
count++;
if(a>number)
{
System.out.println("偏大");
}
else if(a<number)
{
System.out.println("偏小");
}
}while(a!=number);
System.out.println("恭喜你猜对了,你猜了"+count+"次");
}
大家快试试,感觉不错的啊!!!
给个赞呗。。。。。。。。。。。