解决方案 »
- java 自动写读写属性文件
- 给点意见
- [org.springframework.web.struts.ContextLoaderPlugIn] - Context initialization fa
- JAX-WS与Axis
- 用Struts遇到的问题
- JSP+SQL SERVER 2000出现错误“无效的描述符索引”?
- 400分求一关于resin和IIS集成的问题
- [请教]byte[]与字符串转换的问题
- Tomcat 5.0的 Bean驻留问题!
- JSP Excel下载的excel比服务器上生成的excel小10个字节
- ear问题 jboss4.2.3
- mysql 自增字段怎么取得下一个自增的值 在线等
while(stra.length>2){
for(int i=0;i<stra.length;i++){
List a=new ArrayList();
if(( i+1)%3==0){
stra.remove[i];
}if(( i+1)%3!=0){
k=0;
a[k]=stra[i];
k++;
}
if(i+1-stra.length/3*3>0){
for(int j=0;j<a.ength;j++){
stra[j]=a[k];
}
}
return stra;}
ArrayList list = new ArrayList();
for (int i = 1; i <= 13; i++) {
list.add(i);
}
int a = 1;
int b = 0;
while (list.size() != 1) {
if (a % 3 == 0) {
list.remove(b);
b--;
} else {
b++;
if (b == list.size()) {
b = 0;
}
}
a++;
}
System.out.println("第" + list.get(0)+"个人剩下了");
you有啊我的帖子第一个就是
String[] stra = new String[] { "N", "O", "P", "Q", "R", "S", "T", "U","V", "W", "X", "Y", "Z" };
BlockingQueue<String> que = new ArrayBlockingQueue<String>(stra.length,true, Arrays.asList(stra));
int currentCalled = 0;
try {
while (que.size() > 1) {
currentCalled++;
if (currentCalled == 3) {
que.poll();
currentCalled = 0;
} else {
que.put(que.poll());
}
}
System.out.print(que.poll());
} catch (InterruptedException ex) {
Logger.getLogger(FinddataServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Test
public void dd(){
String[] arrs = {"N", "O", "P", "Q", "R", "S", "T", "U","V", "W", "X", "Y", "Z"};
//总人数
int len = arrs.length;
//出局人数
int count = 0;
//报数器
int idx = 1;
//死循环 i%len为数组下标
for(int i=0;;i++){
//已经出局,路过
if("OUT".equals(arrs[i%len])) continue;
//剩余最后一人
if(count==len-1){
System.out.println("游戏结束,最后胜利者为: "+arrs[i%len]);
break;
}
//报到为3或3的倍数.要出局
if(idx%3==0){
System.out.println(arrs[i%len]+"出局.");
arrs[i%len] = "OUT";
count ++;
}
//报数器+1
idx++;
}
}