5n个人围成圈,报数为m的出局顺序问题

import java.util.ArrayList;
import java.util.List;

public class TestCircle {
  public static void to(int total, int number) {
    List<Integer> list = new ArrayList<Integer>(total);
    for (int i = 1; i <= total; i++) {
      list.add(i);
    }
    int begin = -1;
    while (total > 0) {
      begin += number;
      System.out.println(list.remove(begin % total));
      begin = (begin % total) - 1;
      total--;
    }
  }

  /**
   * @param args
   */
  public static void main(String[] args) {
    TestCircle.to(10, 3);
  }
}

你可能感兴趣的:(java)