我想请求一些帮助,将此代码转换为二维数组。我不是要求修复代码,只是一个起点或其他东西,因为数组确实是我编码的弱点。这是代码:
import java.io.*;
import java.util.*;
public class rubix
{
public static void main(String[] args)
{
String[] one = {"red","red","red","red","red","red","red","red","red"};
String[] two = {"blue","blue","blue","blue","blue","blue","blue","blue","blue"};
String[] three = {"yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow","yellow"};
String[] four = {"green","green","green","green","green","green","green","green","green"};
String[] five = {"orange","orange","orange","orange","orange","orange","orange","orange","orange"};
String[] six = {"white","white","white","white","white","white","white","white","white"};
//Output each side of the rubix cube
output(one, 1);
output(two, 2);
output(three, 3);
output(four, 4);
output(five, 5);
output(six, 6);
}
//Output function, will output first the num
public static void output(String[] side, int num)
{
int i,j;
int x = 0;
System.out.println("Side: "+num);
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
System.out.print(side[x]+"\t");
x++;
}
System.out.println();
}
System.out.println();
System.out.println();
}
}