基础练习题

11 多少个互不相同且无重复数字的三位数

2023-09-25  本文已影响0人  北极的大企鹅

题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
程序分析:

可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。

思路:


 1     public class _011PrintThreeArray {
 2 
 3     public static void main(String[] args) {
 4         printThreeArray();
 5     }
 6     
 7      
 8     private static void printThreeArray() {
 9         int count = 0;
10         System.out.println("这样的组合有:");
11         for (int x = 1; x < 5; x++) {
12             for (int y = 1; y < 5; y++) {
13                 for (int z = 1; z < 5; z++) {
14                     if (x != y && y != z && z != x) {
15                         count++;
16                         
17                         System.out.print(x * 100 + y * 10 + z+" ");
18                     }
19                 }
20             }
21         }
22         System.out.println();
23         System.out.println("共有" + count + "个三位数");
24     }
25 }
 
上一篇 下一篇

猜你喜欢

热点阅读