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

利用真伪选猴子大王

2012-12-25 
利用真假选猴子大王public class Mokey {public static void main (String[] args){boolean[] arr new b

利用真假选猴子大王
public class Mokey {
  public static void main (String[] args){
  boolean[] arr = new boolean[500];
  for( int i=0; i<arr.length; i++){
  arr[i] = true;
  }
 
int len = arr.length;
  int countNum = 0;
int index = 0;

while( len > 1 ){
if( arr[index] == true ){
countNum ++;
    if(countNum == 3 ){  //置为false
  countNum = 0;
  arr[index] = false;
  len --;
    }
    }
    index++;
   
    if( index == arr.length ) {
    index=0;
     }
    }

for(int i=0; i<arr.length; i++){
if( arr[i]==true ){
System.out.println(i);
  }
}
  }
}

热点排行