/*
*输入n个人,围成一个m圈,叫到M,提出队伍,知道队伍只剩下一个人,求编号;
* */
public class JS7 {
public static void main(String[] args) {
ArrayList<Integer> array =new ArrayList<Integer>();
Scanner sc =new Scanner(System.in);
System.out.println("请输入人数:");
int n =sc.nextInt();
System.out.println("请输入报数:");
int m =sc.nextInt();
for(int i =1 ; i<=n; i++){
array.add(i);
}
int point=0 ,number =1; //number数数
while(array.size()>1){
if(number%m==0){
array.remove(point);
--point; //集合元素会自动上移
}
++point;
++number;
if(point>array.size()-1){
point=0;
}
}
System.out.println(array.get(0));
}
}
|
|