需要使用Java with matrix的帮助吗
我正在学习,有点小麻烦。 我必须在图片上建立这样的矩阵 但我不能在那个地方放星星需要使用Java with matrix的帮助吗,java,matrix,Java,Matrix,我正在学习,有点小麻烦。 我必须在图片上建立这样的矩阵 但我不能在那个地方放星星 public static void main(String[] args) { int[][] twoD = new int[5][5]; int i, j, k = 1; for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) { twoD[i][j] = k; k++;
public static void main(String[] args) {
int[][] twoD = new int[5][5];
int i, j, k = 1;
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++) {
twoD[i][j] = k;
k++;
}
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++)
System.out.print(twoD[i][j] + " ");
System.out.print("\n");
}
}
这是我的代码,请帮助查找您可以从a中获取答案,然后像这样稍加修改
public static void printCross(int size, char display)
{
int count = 0; //add a counter
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) {
count++; //increment each index we come across
if (row == col || row + col == size - 1) {
//print out the X using teh given display character
System.out.print(String.format("%-3s", display));
} else {
//print out the current count
System.out.print(String.format("%-3s", count));
}
}
System.out.println();
}
}
我找到了我认为最简单的方法
public static void main(String args[]){
String[][] Matrix = { {" *"," 2"," 3"," 4"," *"} , {" 6"," *"," 8"," *","10"} , {"11","12"," *","14","15"} , {"16"," *","18"," *","20"} , {" *","22","23","24"," *"}};
for(int i=0; i< Matrix.length; i++){
for(int j=0;j < Matrix.length; j++){
System.out.print(Matrix[i][j]+" ");
}
System.out.println("");
}
}
你可以用下面这个问题的答案来解决你的许多问题,我会试试。
public static void main(String args[]){
String[][] Matrix = { {" *"," 2"," 3"," 4"," *"} , {" 6"," *"," 8"," *","10"} , {"11","12"," *","14","15"} , {"16"," *","18"," *","20"} , {" *","22","23","24"," *"}};
for(int i=0; i< Matrix.length; i++){
for(int j=0;j < Matrix.length; j++){
System.out.print(Matrix[i][j]+" ");
}
System.out.println("");
}
}