java m取n 重复 不重复 排列组合 for循环嵌套递归
package com.file.read;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.Random;public class CharacterCompose {public static SimpleDateFormat formatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");/** * * **/public static void main(String[] args) {char[] chs = { 'a', 'b', 'c', '1', '2', '3', '4', '5', 'd', 'e', 'f','g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r','s', 't', 'u', 'v', 'w', 'x', 'y', 'z', '6', '7', '8', '9' };char[] chs = { 'A', 'B', 'C', 'D'};//duplicate(chs) ;//notDuplicate(chs);//int a = 1838265625;//Random r = new Random();//duplicate(chs, r.nextInt(a)+1) ;//long numb = 1;//for(int i = 0; i < 6; i++) {//numb = numb * chs.length;//}//System.out.println("重复:::"+numb);a = 1168675200;//r = new Random();//notDuplicate(chs, r.nextInt(a)+1) ;//numb = 1;//for(int i = 0; i < 6; i++) {//numb = numb * (chs.length-i);//}//System.out.println("不重复:::"+numb);//char[] chs = { 'A', 'B', 'C', 'D', 'E', 'F'};//总数int total = 0;//取n个字符int n = 6;/不能重复boolean ifNotSame = true;if(n > 1 && n <= chs.length) {for(int i = 0; i < chs.length; i++) {total = total+loop(0, chs.length, chs, String.valueOf(chs[i]), 1, n-1,ifNotSame);}}String desc = "重复";if(ifNotSame) {desc = "不重复";}System.out.println(chs.length+"取" + n + desc + "的排列组合个数为" + total);///****/total=0;ifNotSame = false;if(n > 1 && n <= chs.length) {for(int i = 0; i < chs.length; i++) {total = total+loop(0, chs.length, chs, String.valueOf(chs[i]), 1, n-1,ifNotSame);}}desc = "重复";if(ifNotSame) {desc = "不重复";}System.out.println(chs.length+"取" + n + desc + "的排列组合个数为" + total);///}//for循环嵌套递归public static int