1. Today basically class is to review the previous OH
Job Joseph Ring, 30 people in a circle, starting from a person to count 1, the next number of 2, count to 9 on (^_^)/~~ bye, out, the next person continues to count 1 .... Ask the remaining 15 people to be Christians? The amount ... Wrong...... The rest of the 15 people are standing in a position. Use an array to solve the ... The initialization is 0, the outgoing is assigned a value of 1, the loop to 1 is not counted, every 9 0, the last 0 will become 1, until the exit 15 people.
Package com.lovo.josephu;/** * Class: Joseph Ring Stance * @author Abe */public class Josephu {public static void main (string[] args) {int[ ] Number = new Int[30];int death = 0;int Dead = 0;do {for (int i = 0; i < number.length; i++) {if (number[i] = = 0) {de ad++;} if (Death < Dead = = 9) {//change dead to determine the number of dead people number[i] = 1;death++;d ead = 0;}}} while (Death < 15),//Change death can determine how many people die after stop for (int x:number) {//for-each loop System.out.print (x);}}}
Feeling wrote one, the other situation: how many people, for example? How many to death? How many died before the end? This kind of problem has been solved ~ ~ ~
Java Programming (13.1)----Loop array application review, Joseph Ring problem