題目:有1、2、3、4個數字,能組成多少個互不相同且無重復數字的三位數?都是多少?
程序分析:可填在百位、十位、個位的數字都是1、2、3、4。組成所有的排列后再去 掉不滿足條件的排列。
程序設計:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public class Wanshu { public static void main(String[] args) { int i= 0 ; int j= 0 ; int k= 0 ; int t= 0 ; for (i= 1 ;i<= 4 ;i++) for (j= 1 ;j<= 4 ;j++) for (k= 1 ;k<= 4 ;k++) if (i!=j && j!=k && i!=k) {t+= 1 ; System.out.println(i* 100 +j* 10 +k); } System.out.println (t); } } |