- package com.itheima.test;
- import java.util.*;
- public class Test100
- {
- public static void main(String[] args)
- {
- // ------------输入学生人数---------------------
- int num = 100; //学生人数.
- int outNum = 14; //第几个人出局.
- // ------------制作列表-------------------------
- List<Integer> list = new ArrayList<Integer>();
- for (int x = 0; x < num; x++)
- {
- list.add(x + 1);
- }
- // --------------------------------------------
- int i = method(list, outNum);
- System.out.println("第"+i+"人");// 返回答案.
- }
- public static int method(List<Integer> list, int outNum)
- {
- int index = -1;
- while (list.size() != 1)
- {
- for (int x = 1; x <= outNum; x++)
- {
- index++;
- if (index >= list.size())
- {
- index = 0;
- }
- }
- list.remove(index);
- index--;
- }
- return list.get(0);
- }
- }
复制代码
答案是 92 对吧? |