package com.ctc.iasms.base.region.action;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class FindLast {
public static int findTheLastOne(int totalNum, int count) {
List<Integer> _list = new ArrayList<Integer>();
for (int i = 1; i <= totalNum; i++) {
_list.add(i);
}
Iterator<Integer> _it = _list.iterator();
int _currentCount = 0;
do {
if (_it.hasNext()) {
_it.next();
_currentCount++;
if (_currentCount == count) {
_it.remove();
_currentCount = 0;
}
} else {
_it = _list.iterator();
}
} while (_list.size() > 1);
return _list.get(0);
}
public static void main(String[] args) {
int _lastIndex = findTheLastOne(10, 3);
System.out.println(_lastIndex);
}
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class FindLast {
public static int findTheLastOne(int totalNum, int count) {
List<Integer> _list = new ArrayList<Integer>();
for (int i = 1; i <= totalNum; i++) {
_list.add(i);
}
Iterator<Integer> _it = _list.iterator();
int _currentCount = 0;
do {
if (_it.hasNext()) {
_it.next();
_currentCount++;
if (_currentCount == count) {
_it.remove();
_currentCount = 0;
}
} else {
_it = _list.iterator();
}
} while (_list.size() > 1);
return _list.get(0);
}
public static void main(String[] args) {
int _lastIndex = findTheLastOne(10, 3);
System.out.println(_lastIndex);
}
}