語句練習題6,語句練習題

來源:互聯網
上載者:User

語句練習題6,語句練習題

有1、2、3、4四個數字,能組成多少個互不相同且無重複數位三位元?都是多少?

 1         String str=""; 2         //首先把所有組成的三位元全部存入字串中 用#隔開 3         for (int i = 1; i <= 4; i++) { 4             for (int j = 1; j <= 4; j++) { 5                 for (int k = 1; k <= 4; k++) { 6                     int num = i * 100 + j * 10 + k; 7                     str = num + "#"+str; 8                 } 9             }10         }11         //按照#把字串進行分割 輸出字串類型的三位元字12         String s[]=str.split("#");13         String a,b,c;14         int count=0;15         //數組遍曆  每個元素截取每一位 進行比較16         for(int i=0;i<s.length;i++){17             a=s[i].substring(0, 1);18             b=s[i].substring(1, 2);19             c=s[i].substring(2, 3);20             if(a.equals(b)==false&&b.equals(c)==false&&a.equals(c)==false){21                 System.out.println(s[i]);22                 count++;23             }24         }25         System.out.println("一共有"+count+"個這樣的數。");
 1         int count1=0; 2         for(int i=1;i<=4;i++){ 3             for(int j=1;j<=4;j++){ 4                 for(int k=1;k<=4;k++){ 5                     //判斷只要三個數字不相同  就組成三位元並輸出 6                     if(i!=j&&i!=k&&j!=k){ 7                         int num1=i*100+j*10+k; 8                         count1++; 9                         System.out.println(num1);10                     }11                 }12             }13         }14         System.out.println("一共有"+count1+"個這樣的數。");

結果:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.