【发布时间】:2011-10-09 11:02:06
【问题描述】:
所以我做了这个猜谜游戏,你的计算机随机选择一个介于 1-100 之间的数字,用户必须猜出正确的数字。我已经做到了,现在我想计算循环重复了多少次,或者用户“猜测”了多少次。
这是当前代码:
int random = 0;
int a;
random = ((int)(Math.random()*100+1));
System.out.println("Guess the number");
do
{
a = Keyboard.readInt();
if (a > random)
{
System.out.println("Less");
}
if (a == random)
{
System.out.println("Correct");
}
if (a < random)
{
System.out.println("More");
}
}
while (a != random);
【问题讨论】:
标签: java loops while-loop