Java Programming (13.1)----Loop array application review, Joseph Ring problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.