首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

约瑟夫出圈有关问题

2012-08-30 
约瑟夫出圈问题import java.util.Scannerpublic class joseph {/** * @param args */public static void

约瑟夫出圈问题

import java.util.Scanner;public class joseph {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner s = new Scanner(System.in);System.out.println("输入总人数:");int total = s.nextInt();System.out.println("输入报名数:");int num = s.nextInt();Node n1 = new Node(1);Node pointer = n1;for (int i = 2; i <= total; i++) {pointer.next = new Node(i);pointer = pointer.next;}pointer.next = n1;while (pointer != pointer.next) {for (int i = 1; i < num; i++) {pointer = pointer.next;}System.out.println(pointer.next.number);pointer.next = pointer.next.next;}System.out.println(pointer.number);}}

热点排行