import java.util.Scanner;
class GuessNumber
{
public static void main(String[] args)
{
int number = (int)(Math.random()*100)+1;
while(true)
{
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个1-100之间的数字:");
int guessNumber=sc.nextInt();
if (guessNumber>number)
{
System.out.println("你猜的数字"+guessNumber+"大了");
}
else if (guessNumber<number)
{
System.out.println("你猜的数字"+guessNumber+"小了");
}
else
{
System.out.println("你猜对了,太棒了");
break;
}
}
}
}
*******************************************************************************
import java.util.Scanner;
class GuessNumber
{
public static void main(String[] args)
{
int number = (int)(Math.random()*100)+1;
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个1-100之间的数字:");
int guessNumber=sc.nextInt();
while(true)
{
if (guessNumber>number)
{
System.out.println("你猜的数字"+guessNumber+"大了");
System.out.print("请输入一个1-100之间的数字:");
guessNumber=sc.nextInt();
}
else if (guessNumber<number)
{
System.out.println("你猜的数字"+guessNumber+"小了");
System.out.print("请输入一个1-100之间的数字:");
guessNumber=sc.nextInt();
}
else
{
System.out.println("你猜对了,太棒了");
break;
}
}
}
}
这个猜数字的游戏的代码,那个更好啊,帮讲一下 |
|