can anyone of you tell me what is wrong with this code and why Eclipse says "The method readInt(String) is undefined for the type Console"?
Thank you in advance!
import java.io.*;
public class Matrix {
private int [] [] matrice;
/* Metodo Costruttore */
Matrix(int i, int j) {
matrice = new int [i] [j];
}
/* reads matrix */
public void leggiMatrix (int ni, int nj) {
int i, j;
for (i=0; i
for (j=0; j
matrice [i] [j] = Console.readInt("Inserire elemento " + i + ", " + j + " : ");
}
/* prints matrix */
public void stampaMatrix(int ni, int nj) {
int i, j;
for (i=0; i
for (j=0; j
System.out.print(matrice[i][j] + " ");
System.out.println();
}
}
}`
UPDATE
/* reads matrix */
public void leggiMatrix (int ni, int nj) {
int i, j;
for (i=0; i
for (j=0; j
matrice [i] [j] = Integer.parseInt(Console.readline("Inserire elemento " + i + ", " + j + " : "));
}
now I get "The Method readLine(Boolean) in the type Console is not applicable for the arguments (String)"
解决方案
This is because readInt isn't a function of Console. What you are looking for is:
//Read input from console
String input = System.console.readLine()
//Convert string to integer
Integer.parseInt(input)