首页 > 其他 > 详细

选出特定编号的猴子

时间:2015-05-25 22:07:27      阅读:100      评论:0      收藏:0      [点我收藏+]

import javax.swing.*;


public class MonkeyKing{
public static void main(String[] args){
String s;
int n,k,m,n1;
s=JOptionPane.showInputDialog("Please enter the amount of the monkey:");//输入对话框
n=Integer.parseInt(s);//将字符串s转变为整型变量
n1=n+1;
s=JOptionPane.showInputDialog("Please enter the first monkey‘s number:");
k=Integer.parseInt(s);//k:first monkey
s=JOptionPane.showInputDialog("please enter the number to eliminate");
m=Integer.parseInt(s);//m:eliminate
int a[]=new int[n+1];
a[0]=0;
System.out.println("the monkey‘s number to eliminate");
for(int i=1;i<a.length;i++)
a[i]=1;
for(int i=1;i<=m;i++){
if(n==1)
break;
else if(i==m){
n--;
i=0;
a[k]=0;
System.out.print(k+" ");
}
do{
k++;
k=k%n1;
}while(a[k]!=1);
}
System.out.println("final number of the monkey:"+k);
}
}

选出特定编号的猴子

原文:http://www.cnblogs.com/sunshinewxz/p/4528901.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!