有1、2、3、4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

package lianxi;

import java.util.*;

public class Sanweishu {

    public static void main(String[] args) {
        String shu = "1234";
        int sum = 0;
        for (int i = 0; i < 4; i++) 
        {
            for (int j = 0; j < 3; j++) 
            {
                String shu1 = shu.replace(shu.substring(i, i + 1), "");
                // System.out.println(shu1.length());
                for (int k = 0; k < 2; k++) 
                {
                    String shu2 = shu1.replace(shu1.substring(j, j + 1), "");
                    // System.out.println(shu2.length());
                    String jieguo = shu.substring(i, i + 1) + shu1.substring(j, j + 1) + shu2.substring(k, k + 1);
                    // 结果输出转换为int
                    sum = sum + 1;
                    System.out.print(" " + new Integer(jieguo));
                }

            }
            System.out.println();
        }
        System.out.println("一共" + sum + "个数");
    }
}

posted @ 2016-05-16 14:27  凌零聆  阅读(966)  评论(0编辑  收藏  举报