Java50道经典习题-程序11 求不重复数字

题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。

 1 public class Prog11 {
 2     public static void main(String[] args) {
 3         int count=0;
 4         int n=0;
 5         for(int i=1;i<5;i++) {
 6             for(int j=1;j<5;j++) {
 7                 if(i==j)
 8                     continue;
 9                 for(int k=1;k<5;k++) {
10                     if(k!=i&&k!=j) {
11                         n=i*100+j*10+k;
12                         System.out.print(n+" ");
13                         if((++count)%5==0);
14                     }
15                 }
16             }
17         }
18         System.out.println();
19         System.out.println("符合条件的数共:"+count+"个");
20     }
21 }
22 /*运行结果
23 123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432 
24 符合条件的数共:24个
25 */

 

posted @ 2019-04-30 16:38  parkour高手  阅读(550)  评论(0编辑  收藏  举报