Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中实现组合字母循环_Java_Loops - Fatal编程技术网

如何在java中实现组合字母循环

如何在java中实现组合字母循环,java,loops,Java,Loops,如何在类似Java的示例输出中使组合字母循环如下 A1 B1 C1 D1 A1 B1 C1 D2 A1 B1 C1 D3 A1 B1 C2 D1 A1 B1 C2 D2 A1 B1 C2 D3 A1 B2 C1 D1 A1 B2 C1 D2 A1 B2 C1 D3 A1 B2 C2 D1 A1 B2 C2 D2 A1 B2 C2 D3 A1 B3 C1 D1 A1 B3 C1 D2 A1 B3 C1 D3 A1 B3 C2 D1 A1 B3 C2 D2 A2 B3 C2 D3 A2 B1 C1

如何在类似Java的示例输出中使组合字母循环如下

A1 B1 C1 D1
A1 B1 C1 D2
A1 B1 C1 D3
A1 B1 C2 D1
A1 B1 C2 D2
A1 B1 C2 D3
A1 B2 C1 D1
A1 B2 C1 D2
A1 B2 C1 D3
A1 B2 C2 D1
A1 B2 C2 D2
A1 B2 C2 D3
A1 B3 C1 D1
A1 B3 C1 D2
A1 B3 C1 D3
A1 B3 C2 D1
A1 B3 C2 D2
A2 B3 C2 D3
A2 B1 C1 D1
A2 B1 C1 D2
A2 B1 C1 D3
A2 B1 C2 D1
A2 B1 C2 D2
A2 B1 C2 D3
A2 B2 C1 D1
A2 B2 C1 D2
A2 B2 C1 D3
A2 B2 C2 D1
A2 B2 C2 D2
A2 B2 C2 D3
A2 B3 C1 D1
A2 B3 C1 D2
A2 B3 C1 D3
A2 B3 C2 D1
A2 B3 C2 D2
A2 B3 C2 D3
对于类似矩阵(36 x 4)的组合。 第1列是A1的18,A2的18。 第2列为6表示B1,6表示B2,6表示B3。 第3列为3表示C1,3表示C2。 第4列为1表示D1,1表示D2,1表示D3。 每列有36个数据。 谢谢。我认为模式是: 主数组有4个元素(
A B C D

  • 我们从A循环到D
  • D有3个元素(从D1到D3)
  • C有2个元素(从C1到C2)
  • B有3个元素(从B1到B3)
  • A有2个元素(从A1到A2)
伪代码:

String[2] A = {"A1","A2"};
String[3] B = {"B1","B2","B3"};
String[2] C = {"C1","C2"};
String[3] D = {"D1","D2","D3"};
for(int i = 0; i < A.length;i++){
   for(int j = 0;j < B.length;j++){
     for(int t = 0; t < C.length;t++){
        for(int e = 0; e < D.length;e++){
            System.out.printfln(A[i] + " " + B[j] + " " + C[t] + " " + D[e]);
        }
     }
   }
}
String[2]A={“A1”,“A2”};
字符串[3]B={“B1”、“B2”、“B3”};
字符串[2]C={“C1”,“C2”};
字符串[3]D={“D1”、“D2”、“D3”};
for(int i=0;i
人们可能会因为我送走一条鱼而攻击我。就这样吧

public class Scratch1
{
    private static class Nibble {
        private String[] symbols;
        private int      numSymbols;
        private int      numRepeats;

        public Nibble(int numRepeats, String... symbols) {
            this.symbols = symbols;
            this.numSymbols = symbols.length;
            this.numRepeats = numRepeats;
        }

        public String toString(int i) {
            return symbols[(i / numRepeats) % numSymbols];
        }
    }

    private static class Column {
        private Nibble firstNibble;
        private Nibble secondNibble;

        public Column(Nibble firstNibble, Nibble secondNibble) {
            this.firstNibble = firstNibble;
            this.secondNibble = secondNibble;
        }

        public String toString(int i) {
            return firstNibble.toString(i) + secondNibble.toString(i);
        }
    }

    public static void main(String[] args)
    {
        Column columns[] = {
            new Column( new Nibble(18, "A"), new Nibble(18, "1", "2")),
            new Column( new Nibble(18, "B"), new Nibble( 6, "1", "2", "3")),
            new Column( new Nibble( 6, "C"), new Nibble( 3, "1", "2")),
            new Column( new Nibble( 3, "D"), new Nibble( 1, "1", "2", "3"))
        };

        for (int i = 0 ; i < 36 ; i++) {
            for (int colNum = 0 ; colNum < columns.length ; colNum++) {
                if (colNum > 0) System.out.print(" ");
                System.out.print(columns[colNum].toString(i));
            }
            System.out.println();
        }
    }
}
公共类Scratch1
{
私有静态类半字节{
私有字符串[]符号;
私有整数符号;
私有整数;
公共半字节(整数、字符串…符号){
这个符号=符号;
this.numSymbols=symbols.length;
this.numRepeats=numRepeats;
}
公共字符串到字符串(int i){
返回符号[(i/numRepeats)%numSymbols];
}
}
私有静态类列{
私人一点一点地吃;
私人蚕食第二蚕食;
公共列(半字节第一半字节、半字节第二半字节){
this.firstNibble=firstNibble;
this.secondNibble=secondNibble;
}
公共字符串到字符串(int i){
返回firstNibble.toString(i)+secondNibble.toString(i);
}
}
公共静态void main(字符串[]args)
{
列[]={
新列(新半字节(18,“A”)、新半字节(18,“1”、“2”),
新列(新半字节(18,“B”)、新半字节(6,“1”、“2”、“3”),
新列(新半字节(6,“C”)、新半字节(3,“1”,“2”),
新列(新半字节(3,“D”),新半字节(1,“1”,“2”,“3”))
};
对于(int i=0;i<36;i++){
for(int colNum=0;colNum0)系统输出打印(“”);
System.out.print(列[colNum].toString(i));
}
System.out.println();
}
}
}

使用两个
循环。具体模式是什么?如何从“A1 B1 C1 D2”过渡到“A1 B1 C2 D3”?从那个到“A1 B2 C2 D1”?从那个到“A1 B2 C1 D2”?这是没有逻辑的。喂吸血鬼帮忙:(