笛卡尔积 生成 SKU 算法

news/2024/7/24 6:17:41 标签: B2B  SKU
public class 笛卡尔积生成SKU {
    private static String[] aa={"a1","a2"};
    private static String[] bb={"b1"};
    private static String[] cc={"c1","c2","c3"};
    private static String[] dd={"d1","d2"};
    private static String[][] xyz={aa,bb,cc,dd};
    private static int counterIndex =xyz.length-1;
    private static int[] counter={0,0,0,0};

    public static void main(String[] args) {
        int myLength=aa.length*bb.length*cc.length*dd.length;
        for (int i=0;i<myLength;i++){
            System.out.print(aa[counter[0]]);
            System.out.print("\t");
            System.out.print(bb[counter[1]]);
            System.out.print("\t");
            System.out.print(cc[counter[2]]);
            System.out.print("\t");
            System.out.print(dd[counter[3]]);
            System.out.println();
            handle();
        }
    }
    public static void handle(){
        counter[counterIndex]++;
        if (counter[counterIndex]>=xyz[counterIndex].length){
            counter[counterIndex]=0;
            counterIndex--;
            if (counterIndex>=0){
                handle();
            }
            counterIndex=xyz.length-1;
        }
    }
}

结果: 

a1	b1	c1	d1
a1	b1	c1	d2
a1	b1	c2	d1
a1	b1	c2	d2
a1	b1	c3	d1
a1	b1	c3	d2
a2	b1	c1	d1
a2	b1	c1	d2
a2	b1	c2	d1
a2	b1	c2	d2
a2	b1	c3	d1
a2	b1	c3	d2

 


http://www.niftyadmin.cn/n/1868218.html

相关文章

ubuntu 安装JDK环境变量配置

export JAVA_HOME/opt/java/jdk1.8.181 export JRE_HOME${JAVA_HOME}/jre export CLASSPATH.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH${JAVA_HOME}/bin:$PATH

RPC例子

首先&#xff0c;定义业务&#xff1a; package com.service;public interface HelloService {String sayHi(String name); }package com.service.impl;import com.service.HelloService;public class HelloServiceImpl implements HelloService{Overridepublic String sayHi(…

枚举工具类

从基础开始&#xff1a; 枚举的定义&#xff1a; public enum SexEnum implements IEnum {Male(1, "男"), Female(2, "女"), Unknown(3, "未知");private int value;private String label;SexEnum(int value, String label) {this.value valu…

JAVA List 排序

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List;public class People {String name;Integer age;Date birthDate;// ...省略 get(),set(),constructorpublic static void main(String…

redis入门 centos 安装配置

redis 安装记录&#xff1a; 1 安装 https://blog.csdn.net/u010651369/article/details/80677464 2 配置可以远程访问 将安装目录下的 redis.conf 中的 bind去掉 具体操作 vi redis.conf 然后 :/bind 找到bind这一行 然后注释掉 然后 按ESC &#xff0c;然后 :wq …

PSI Probe tomcat监控软件

tomcat-users.xml 添加 <role rolename"manager"/><role rolename"tomcat"/><role rolename"manager-gui"/><user username"tomcat" password"tomcat" roles"manager,tomcat,manager-gui"…

spring security principal credentials authorities details authenticated

spring security在进行认证时&#xff0c;会将用户名和密码封装成一个Authentication对象&#xff0c;在进行认证后&#xff0c;会将Authentication的权限等信息填充完全返回。Authentication会被存在SecurityContext中&#xff0c;供应用之后的授权等操作使用。此处介绍下Auth…