所以我制作了这个猜谜游戏,计算机随机挑选1-100之间的数字,用户必须猜出正确的数字。我已经完成了这个工作,现在我想计算循环有多少次重复自己,如果你可能说,或者多少次用户“猜测”。Java:计算do/while循环的数量
这是当前的代码:
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);