package test;
import java.util.LinkedList;
import java.util.List;
public class Test4 {
public static void main(String[] args){
Joesephe joesephe = new Joesephe();
int count = 1 ;
int index = 0 ;
for( int i = 1 ; i < 11 ; i++){
joesephe.addElemnet(i);
}
while(joesephe.getLength() != 1){
if(joesephe.getElement(index) == 0){
index = (index + 1) >= joesephe.getSize() ? 0 : (index + 1) ;
continue;
}
if(count == 3){
joesephe.changeElement(index, 0);
}
count = (count + 1) == 4 ? 1 : count + 1;
index = (index + 1) >= joesephe.getSize() ? 0 : (index + 1) ;
}
for(int i = 0 ;i<joesephe.getSize() ; i++){
if(joesephe.getElement(i) != 0 ){
System.out.println(joesephe.getElement(i));
}
}
}
}
class Joesephe{
private List<Integer> list = new LinkedList<Integer>();
private int changCount = 0;
public void addElemnet(Integer element){
list.add(element);
}
public void deleteElement(int index){
list.remove(index);
}
public void changeElement(int index,Integer element){
list.remove(index);
list.add(index, element);
changCount ++;
}
public Integer getLength(){
return list.size() - changCount;
}
public Integer getSize(){
return list.size();
}
public Integer getElement(int index){
return list.get(index);
}
}