猜数字小游戏
代码如下:
import java.util.Scanner;
class GuessNumber1
{
public static void main(String[] args){
double d=Math.random();
int number=(int)(d*100)+1;
int count=0;
while(true){
System.out.print("请输入你所猜的数字(1-100):");
Scanner sc=new Scanner(System.in);
int guessnumber=sc.nextInt();
count++;
if(guessnumber>number){
System.out.println(guessnumber+"相比目标数大了");
}
else if(guessnumber<number){
System.out.println(guessnumber+"相比目标数小了");
}
else
{
System.out.println("恭喜你,回答正确!");
if(count<2)
{
System.out.println("你"+count+"次就猜对了,牛逼!");
}
else if(count>1&&count<6){
System.out.println("你猜"+count+"次就猜对了,不错!");
}
else if(count>5&&count<11){
System.out.println("你猜"+count+"次才猜对,还算可以!");
}
else if(count>11)
{
System.out.println((count-1)+"次都猜不中,你可以放弃了骚年,这种高智商的游戏明显不适合你,回家洗洗睡吧!");
}
break;
}
}
}
}
|
|