我不确定要在我的二维数组中的某个位置查找字符时需要使用什么。我所试图做的是让用户输入的行数和列数和获取价值的通讯员到二维数组中的两个变量,检索,然后它的阵列尝试使用java中的行号和列号在二维数组中找到一个字符
import java.util.*;
public class twoDimension {
public static void printRow(int[] row) {
for (int i : row) {
System.out.print(i);
System.out.print("\t");
}
System.out.println();
}
public static void main(String[] args) {
int twoDm[][]= new int[3][4];
for (int i = 0; i < twoDm.length; i++) {
for (int j = 0; j < twoDm[i].length; j++) {
twoDm[i][j] = (int)(Math.random()*10); // we decided to randomise the numbers in the array.
}
}
for(int[] row : twoDm) {
printRow(row);
}
System.out.println("Enter a number with the format 'xy'. x is the row number and y the column number. Whenever you want to quit out, input 'quit'.");
String xy;
while (!xy.equalsIgnoreCase("quit")) {
Scanner scanner = new Scanner(System.in);
String xy = scanner.nextLine();
char x = xy.charAt(0);
char y = xy.charAt(1);
// fetching the character in the array and displaying it
// setting it to 0
// displaying the array again
}
}
}
中设置为0 PS:我设法找到了如何在没有逗号或括号的情况下显示数组,但我不确定是否要移除显示中的空格。
通过“空格在显示“你的意思是由'System.out.print(”\ t“)''创建的标签吗? –
是的,我做,对不起 – Dracose