I have an array as below:
String[][] x = {{"A1", "A2"}, {"B1", "B2"}, {"C1", "C2"}};
I want to print out the element connections like this:
A1-B1-C1
A1-B1-C2
A1-B2-C1
A1-B2-C2
A2-B1-C1
A2-B1-C2
A2-B2-C1
A2-B2-C2
Is there any suggestion? Thanks.
package staticTryOuts;
class Test
{
public static void main(String[] args) {
String[][] x = {{"A1", "A2"}, {"B1", "B2"}, {"C1", "C2"}};
for(int i=0;i<x[0].length;i++) {
for(int j=0;j<x[1].length;j++) {
for(int k=0;k<x[2].length;k++) {
System.out.println(x[0][i]+"-"+x[1][j]+"-"+x[2][k]);
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.