Exercise1_3_37
来源:互联网 发布:网络协议栈是什么 编辑:程序博客网 时间:2024/06/05 23:40
package chapterone;import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Josephus { public static void main(String[] args) { Queue<Integer> queue = new LinkedList<Integer>(); System.out.println("start"); System.out.println("————————————————"); Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); scan.close(); for (int i = 0; i < N; i++) { queue.add(Integer.valueOf(i)); } int k = 0; while (!queue.isEmpty()) { int x = queue.poll(); if ((++k) % M == 0) { System.out.print(x + " "); } else { queue.add(Integer.valueOf(x)); } } }}
0 0