import java.util.*;
class Node {
public Node prior;
public Node next;
public int people; public Node(int people) {
this.people = people;
}
}class Go
{
public int num = 1;
public Node p;
public Node head;
public boolean a = true;
public int peopleNum;
public Go(int peopleNum)
{
head = new Node(1);
Node temp = head; //创建链表
for (int i = 2; i <= peopleNum; i++)
{
temp.next = new Node(i);
temp.next.prior = temp;
temp = temp.next;
}
//双向循环
head.prior = temp;
temp.next = head;
p = head;
} public void count()
{
if (a==true)
{
while(num % 7 !=0 && ( num %10 !=7 || ( num /10)%10 !=7))
{
System.out.print(p.people + " -> ");
p = p.next;
num++;
}
System.out.print(p.people);
a = false;
p = p.prior;
}
else
{
while(num % 7 !=0 && ( num %10 !=7 || ( num /10)%10 !=7))
{
System.out.print(p.people + " -> ");
p = p.prior;
num ++;
}
System.out.print(p.people);
a = true;
p = p.next;
}
               System.out.println("    num:" + num + " \npress enter key to enter next round");
num++;
}
}public class Double
{
public static void main(String args[])
{
System.out.println("输入人数:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Go L=new Go(n);
L.count();
}
}

解决方案 »

  1.   

    构造函数中未对peopleNum初始化,class Go
    {
    public int num = 1;
    public Node p;
    public Node head;
    public boolean a = true;
    public int peopleNum;
    public Go(int peopleNum)
    {
    this.peopleNum = peopleNum; //你忘记对peopleNum进行初始化
    head = new Node(1);
    Node temp = head;//创建链表
    for (int i = 2; i <= peopleNum; i++)
    {
    temp.next = new Node(i);
    temp.next.prior = temp;
    temp = temp.next;
    }
      

  2.   

    你这是if的两个分支,只能进到一个里面啊,
    if (a==true)
    {
    while(num % 7 !=0 && ( num %10 !=7 || ( num /10)%10 !=7))
    {
    System.out.print(p.people + " -> ");
    p = p.next;
    num++;
    }
    System.out.print(p.people);
    a = false;
    p = p.prior;
    }
    else
    {
    while(num % 7 !=0 && ( num %10 !=7 || ( num /10)%10 !=7))
    {
    System.out.print(p.people + " -> ");
    p = p.prior;
    num ++;
    }
    System.out.print(p.people);
    a = true;
    p = p.next;
    }
      System.out.println(" num:" + num + " \npress enter key to enter next round");
    num++;
    }
    }
      

  3.   


    楼主的这个全局peopleNum本来就是多余的,赋值否都一样。
      

  4.   

    我为楼主改了下,主要就是改了count方法,不知道是不是想要的。package coc;import java.util.*;class Node {
    public Node prior;
    public Node next;
    public int people; public Node(int people) {
    this.people = people;
    }
    }class Go {
    public int num = 1;
    public Node p;
    public Node head;
    public boolean a = true;
    public int peopleNum; public Go(int peopleNum) {
    head = new Node(1);
    Node temp = head; for (int i = 2; i <= peopleNum; i++) {
    temp.next = new Node(i);
    temp.next.prior = temp;
    temp = temp.next;
    }
    head.prior = temp;
    temp.next = head;
    p = head;
    } public void count() {
    boolean order=true;

    while(true){
    System.out.print(p.people + " -> ");
    if (num % 7 != 0 && (num % 10 != 7 || (num / 10) % 10 != 7)) { }else{
    order=!order;
    }
    if(order){
    p = p.next;
    }else{
    p = p.prior;
    }
    num++;
    } }
    }public class Double {
    public static void main(String args[]) {
    System.out.println("People Number:");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Go L = new Go(n);
    L.count();
    }
    }
      

  5.   

    再次更新下,发现楼主的“是数到7的倍数或者含有7这个数”判断条件写的不对。
    并且增加了log, 谁报什么数也打出来了。注意: 由于是循环报数,故改程序没有结束的时候。 也可能是我没有领会楼主结束报数的条件。package coc;import java.util.*;class Node {
    public Node prior;
    public Node next;
    public int people; public Node(int people) {
    this.people = people;
    }
    }class Go {
    public int num = 1;
    public Node p;
    public Node head;
    public boolean a = true;
    public int peopleNum; public Go(int peopleNum) {
    head = new Node(1);
    Node temp = head; for (int i = 2; i <= peopleNum; i++) {
    temp.next = new Node(i);
    temp.next.prior = temp;
    temp = temp.next;
    }
    head.prior = temp;
    temp.next = head;
    p = head;
    } public void count() {
    boolean order=true;

    while(true){
    System.out.print(p.people + "(num:" + num + ") -> ");
    if (num % 7 == 0 || String.valueOf(num).contains("7")) {
    order=!order;
    }
    if(order){
    p = p.next;
    }else{
    p = p.prior;
    }
    num++;
    } }
    }public class Double {
    public static void main(String args[]) {
    System.out.println("People Number:");
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Go L = new Go(n);
    L.count();
    }
    }