我正在尝试解决约瑟夫斯问题,但我不允许使用其他人的代码片段。考虑到这一点,我的代码中有 27 个错误,但不知道如何修复它。你能不能向我解释为什么它不能编译。我想看看我的逻辑是否有缺陷,但我无法测试它,因为它不会编译。任何其他提示都非常受欢迎!这是我的代码:
import java.util.*;
public class Josephus
{
public class Link
{
public int num;
public Link next;
public Link (int d)
{
num = d;
next = null;
}
}
public class Main
{
Scanner in = new Scanner(System.in);
System.out.println("How many players");
int numPlayers = in.nextInt();
Link first, last;
first = last = new Link (1);
for(int k=2; k<=numPlayers; k++)
{
last.next = new Link(k);
last = last.next;
}
last.next = first;
System.out.println("How many skips");
int m = in.nextInt();
for (int g=0; g<numPlayers; g++)
{
for (int k=0; k<=m; k++);
{
last = last.next;
}
last.next;
last = last.next;
}
}
}