当前位置: 编程技术>java/j2ee
java 实现约瑟夫环的实例代码
来源: 互联网 发布时间:2014-10-28
本文导语: 代码如下:import java.io.BufferedInputStream;import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class Josephus { private static class Node{ int No; Node next; public Node(int No){ this.No=No; ...
代码如下:
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Josephus {
private static class Node{
int No;
Node next;
public Node(int No){
this.No=No;
}
}
public static void main(String[] args) {
int totalNum,cycleNum;
List list = new ArrayList();
Scanner cin = new Scanner(new BufferedInputStream(System.in));
System.out.println("请输入总人数:");
totalNum=cin.nextInt();
System.out.println("请输入报数人数:");
cycleNum=cin.nextInt();
Node header = new Node(1);
Node pointer = header;
for(int i=2;i