java里保证名称不重复_java m取n 重复 不重复 排列组合 for循环嵌套递归.docx

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值