package T4;
class People{
public int identifier; //编号
public int new_identifier;
public boolean state; //圈内或圈外
static int i = 0;
public People(){
new_identifier = identifier = i = i+1;
state = true;
}
}
class Test4 {
private People[] people;
public Test4(){
people = new People[100];
}
public void gamerunning(){
int peopleinrool = 100;
while(peopleinrool > 1){//当剩下一人,游戏结束
for(int i = 0; i < 100 ;i++){
int newid = 1;
if(people[i].state){
if(people[i].new_identifier%3 == 0){
people[i].state = false;
peopleinrool--;
}
else
people[i].new_identifier = newid++;
}
}
}
for(int i = 0; i < 100; i++)
if(people[i].state == true){
System.out.print(people[i].identifier);
}
}
public static void main(String[] args){
Test4 test4 = new Test4();
test4.gamerunning();
}
}
class People{
public int identifier; //编号
public int new_identifier;
public boolean state; //圈内或圈外
static int i = 0;
public People(){
new_identifier = identifier = i = i+1;
state = true;
}
}
class Test4 {
private People[] people;
public Test4(){
people = new People[100];
}
public void gamerunning(){
int peopleinrool = 100;
while(peopleinrool > 1){//当剩下一人,游戏结束
for(int i = 0; i < 100 ;i++){
int newid = 1;
if(people[i].state){
if(people[i].new_identifier%3 == 0){
people[i].state = false;
peopleinrool--;
}
else
people[i].new_identifier = newid++;
}
}
}
for(int i = 0; i < 100; i++)
if(people[i].state == true){
System.out.print(people[i].identifier);
}
}
public static void main(String[] args){
Test4 test4 = new Test4();
test4.gamerunning();
}
}
解决方案 »
- 回答马上给分!!!org.hibernate.type.SerializationException: could not deserialize
- 菜鸟请教 对象的比较问题?现在有person类,person类中有两个属性 String name; int score;怎样将person类的对象按score排序?
- 我在www.javootoo.com下载了LookAndFeel,不知道怎么用
- 各位大哥!!!!求救啊!~!
- jdk1.5下编译Vector类的安全操作提示?
- sturts验证问题
- 如何判断一个变量的数据类型是int型的?
- 把两个类写到一个文件中怎样编译?
- 谁有<<JAVA核心技术 卷II>>下载地址崩 高分
- 键盘事件(快捷键)发生时焦点的移动问题
- TreeMap<string,MyClass> 怎么按照排序
- 请教等所有Thread结束后再往下走的问题
只是初始化了数组长度
里面的元素没有初始化
楼主不妨参考下如下代码
import java.util.Scanner;/**
* @ClassName: Test4
* @Description: TODO(这里用一句话描述这个类的作用)
* @author A18ccms a18ccms_gmail_com
* @date 2012-2-3 下午12:30:38
*/class Test4 {
private static class Node {
public int no;// 编号
public Node next;// 下一个节点
public Node(int no) {
this.no = no;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入总人数:");
int totalNum = scanner.nextInt();
System.out.print("请输入报数的大小:");
int cycleNum = scanner.nextInt();
Node header = new Node(1);
Node pointer = header;
for (int i = 2; i <= totalNum; i++) {
//指向下一个节点
pointer.next = new Node(i);
//前移
pointer = pointer.next;
}
//形成循环链表 尾部指向头部
pointer.next = header;
// 初始化环形链表结束
System.out.println("以下是出列的顺序:");
while (pointer != pointer.next) {
for (int i = 1; i < cycleNum; i++) {
//从头开始
pointer = pointer.next;
}
System.out.println(pointer.next.no);
//前进
pointer.next = pointer.next.next;
}
System.out.println(pointer.next.no);
}
}