java - Converting 1 dimensional array to 2 dimensional array -
i request converting code 2 dimensional array. i'm not asking fix code, starting point or since arrays weak point in coding. here code:
import java.io.*; import java.util.*; public class rubix { public static void main(string[] args) { string[] 1 = {"red","red","red","red","red","red","red","red","red"}; string[] 2 = {"blue","blue","blue","blue","blue","blue","blue","blue","blue"}; string[] 3 = {"yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow"}; string[] 4 = {"green","green","green","green","green","green","green","green","green"}; string[] 5 = {"orange","orange","orange","orange","orange","orange","orange","orange","orange"}; string[] 6 = {"white","white","white","white","white","white","white","white","white"}; //output each side of rubix cube output(one, 1); output(two, 2); output(three, 3); output(four, 4); output(five, 5); output(six, 6); } //output function, output first num public static void output(string[] side, int num) { int i,j; int x = 0; system.out.println("side: "+num); for(i = 0; < 3; i++) { for(j = 0; j < 3; j++) { system.out.print(side[x]+"\t"); x++; } system.out.println(); } system.out.println(); system.out.println(); } }
maybe looking 3 dimensional array, check following:
public static void main(string[] args) { string[][][] rubik={ { {"red","red","red"}, {"red","red","red"}, {"red","red","red"} },{ {"blue","blue","blue"}, {"blue","blue","blue"}, {"blue","blue","blue"} },{ {"yellow","yellow","yellow"}, {"yellow","yellow","yellow"}, {"yellow","yellow","yellow"} },{ {"green","green","green"}, {"green","green","green"}, {"green","green","green"} },{ {"orange","orange","orange"}, {"orange","orange","orange"}, {"orange","orange","orange"} },{ {"white","white","white"}, {"white","white","white"}, {"white","white","white"} } }; output(rubik, 0); output(rubik, 1); output(rubik, 2); output(rubik, 3); output(rubik, 4); output(rubik, 5); } public static void output(string[][][] rubik, int num) { int i,j; int x = 0; system.out.println("side: "+num); for(i = 0; < 3; i++) { for(j = 0; j < 3; j++) { system.out.print(rubik[num][i][j]+"\t"); x++; } system.out.println(); } system.out.println(); system.out.println(); }
to clarify little bit:
rubik[s][c][r] s=side c=column on side s r=row on side s
Comments
Post a Comment