import java.util.ArrayList; public class test7 { /* * 约瑟夫环 */ public static void main(String[] args) { System.out.println(getluck(8)); } public static int getluck(int n) { ArrayList<Integer> a1 = new ArrayList<>(); for (int i = 1; i <= n; i++) { a1.add(i); } int count = 1; for (int i = 0; a1.size()!=1; i++) { if (i==a1.size()) { i = 0; } if (count %3==0) { a1.remove(i); i--; } if (a1.size()==1) { break; } count++; } return a1.get(0); } }