为了账号安全,请及时绑定邮箱和手机立即绑定

这个程序怎么没有输出结果。运行老长时间了。

package TestArray;

public class Count3Quit2 {
	public static void main(String [] args) {
		KidCircle kc = new KidCircle(500);
		int countNum = 0;
		Kid k  = kc.first;
		while(kc.count > 1) {
			countNum++;
			if(countNum == 3) {
				countNum =0;
				kc.delete(k);
			}
			k = k.right;
		}
		System.out.println(kc.first.id);
		}
}
	
class Kid{
	int id;
	Kid left;
	Kid right;
	}

class KidCircle{
	int count = 0;
	Kid first , last;
	 
	KidCircle(int n){
		for(int i = 0; i < n; i++) {
			add();
		}
	}
	
	void add() {
		Kid k = new Kid();
		k.id = count;
		if(count <= 0) {
			first = k;
			last = k;
			k.left = k;
			k.right = k;
			first.left = k;
			last = k;
		}
		count++;
	}
	
	void delete(Kid k) {
		if (count <= 0) {
			return;
		}else if(count == 1){
			first = last =null;
		}else {
			k.left.right = k.right;
			k.right.left = k.left;
		}
	}
}


正在回答

1 回答

首先你的代码是个死循环,其次没看懂你想表达什么,做了一堆的无用功,以表示自己的能耐吗?

 while(kc.count > 1)这里的count一直是500,所以此处的条件一直成立,你并没有给出一个条件让它跳出循环

0 回复 有任何疑惑可以回复我~
#1

慕九州4223353 提问者

谢谢啊,其实我没弄懂啥意思,先抄下来运行一下。少写了一段程序。
2017-09-15 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

这个程序怎么没有输出结果。运行老长时间了。

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信