題目:有1、2、3、4個數字,能組成多少個互不相同
且無重復數字的三位數?都是多少?
程序分析:可填在百位、十位、個位的數字
都是1、2、3、4。組成所有的排列后再去掉不滿足條件的排列。
public class 第十一題組成無重復數字的三位數 { public static void main(String[] args) { int count = 0; //統計滿足條件的數的個數
for(int i=1; i<5; i++) { for(int j=1; j<5; j++) { for(int k=1; k<5; k++) { if(i!=j && j!=k && i!=k) { count++; System.out.println(i+""+j+""+k); } } } } System.out.println("合計:"+count + "個"); } }