/**
* 7-2
* Joseph question
* Programmed by the keyboard to receive a value of n, from the number of 1 people began to count,
* The man who counted to 7
* What is the number of the last person left in the output */
import java.util.*;p Ublic class test {public static void main (String[] args) {System.out.println ("Enter a value of n from the keyboard"); Scanner input = new scanner (system.in); Int num = input.nextint (); node[] array = new node[num+1];//declares n+1 node//initialization node for (int i = 1; i < num; i++) Array[i] = new node (1, i+1);//Set the last node to point to the first node array[num] = new node (1, 1);//The game starts with a node pointing to the first person int k = num;for (int i = 0; i < num-1; i++)//keep circulating until the last person is left {for (int j = 0; ;) {if (j &NBSP;<&NBSP;7)//number to 7th person {k = array[k].readnext (); J += array[k].readdata ();} Elsebreak;} Array[k].setdata (0);} Enter the last remaining person for (int i = 1; i < num+1; i++) if (array[i].readData () == 1) System.out.print (" " + i + " ");}} class node{private int m_data;private int m_next;//Constructor node (Int data, int next) {M_data = data;m_next = next;} Sets the data value of the node void setdata (int data) {m_data = data;} Reads the data value of the node int readdata () {return m_data;} Sets the node's point to void setnext (Int next) {m_next = next;} Read node to int readnext () {return m_next;}}
Those years, learn together Java 7-2