这是我到目前为止编写的代码,我想添加每只老鼠解决的总数,但它显示的数量不正确。
鼠标 1 解决了多少个迷宫?4
鼠标 2 解决了多少迷宫?0
老鼠3解决了多少迷宫?1
鼠标 4 解决了多少迷宫?4
老鼠 1 解决了多少个迷宫?2
老鼠 2 解决了多少个迷宫?3
老鼠 3 解决了多少个迷宫?0
老鼠 4 解决了多少个迷宫?4
鼠标解决了 8。老鼠解决了 8
import java.util.Random;
public class ratloop {
public static void main(String[] args) {
mazeRun();
System.exit(0);
}
public static void mazeRun()
{
Random randomGenerator = new Random();
int mouseTest;
int mouseSolved = 1;
for (mouseTest= 1; mouseTest <=4; mouseTest++)
{
mouseSolved = randomGenerator.nextInt(5);
System.out.println("How many mazes did mouse " + mouseTest + " solve? " + mouseSolved);
mouseSolved = mouseSolved + mouseTest;
}
int ratTest;
int ratSolved = 1;
for (ratTest= 1; ratTest <=4; ratTest++)
{
ratSolved = randomGenerator.nextInt(5);
System.out.println("How many mazes did rat " + ratTest + " solve? " + ratSolved);
ratSolved = ratSolved + ratTest;
}
System.out.println("The mouse solved " + mouseSolved + " . And the rats solved " + ratSolved);
}
}