java基礎練習 15,java基礎練習

來源:互聯網
上載者:User

java基礎練習 15,java基礎練習

import java.util.Scanner;public class Fiftheen {/*有n個人圍成一圈,順序排號。從第一個人開始報數(從1到3報數),凡報到3的人退出圈子,問最後留下的是原來第幾號的那位。*/public static void main(String[] args){Scanner input=new Scanner(System.in);System.out.print("請輸入圍圈的人數:");int a=input.nextInt();System.out.println(" ");int[] b=new int[a];int i,j,k=0,m=0,n=0;for(i=1;i<a;i++)b[i]=i;while(a!=1){if(k>0){if(n==1){b[1]=99099;m=2;}else if(n==2){b[0]=99099;m=1;}elsem=0;}n=0;for(i=m;i<a;i++){n++;if(n==3){n=0;b[i]=99099;}}for(i=0;i<a;i++)if(b[i]==99099){for(j=i;j<a-1;j++)b[j]=b[j+1];a--;i--;}k++;}System.out.println("最後留下的為原來的"+(b[0]+1)+"號。");}}

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.