我试图通过使用空格作为分隔符将“sisestus”拆分为不同的单词,但是仅使用 sc.next() 不允许我输入带空格的字符串,所以我读到我应该使用 .nextLine(),但它根本不起作用。我该如何解决?
public class Sisestamine {
int read;
int veerud;
double Maatriks[][];
java.util.Scanner sc = new java.util.Scanner(System.in);
Sisestamine() {
System.out.println("Enter matrix dimensions (format NxM)");
String[] abi = sc.next().split("x");
this.read = Integer.parseInt(abi[0]);
this.veerud = Integer.parseInt(abi[1]);
this.Maatriks = new double[read][veerud];
System.out.println("Enter the matrix: (x x x x etc..)");
for (int i = 0; i < read; i++) {
String sisestus = sc.next();
//String sisestus = sc.nextLine();
abi = sisestus.split(" ");
System.out.print(abi);
for (int j = 0; j < abi.length; j++) {
this.Maatriks[i][j] = Double.parseDouble(abi[j]);
}
}
}
}