java编程:猜数字游戏。提前用Random生成一个1-10的随机数,保存在变量guess中,
最佳答案
///程序参考:
public static void main(String[] srgs) {
Scanner sc=new Scanner(System.in);
Random rand =new Random();
int guess=rand.nextInt(100)+1;
while (true)
{
System.out.printf("请输入您猜的数:(1-100)");
int iInput=sc.nextInt();
if (iInput > guess)
{
System.out.printf("您猜大了!") ;
}
else if (iInput < guess)
{
System.out.printf("您猜小了!") ;
}
else if (iInput == guess)
{
System.out.printf("恭喜您,猜对啦!");
break;
}
}
}
其他回答
其它网友回答:
基础学习扎实应该很容易做。