I have got n lines of numbers , all containing equal number of numbers lets say m , how to store them in 2d array
1 5 7 9
2 3 4 6
3 4 5 8
Note that here value of n and m is not given .
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
Scanner sc=new Scanner(System.in);
while(sc.hasNextLine())
{
String line=br.readLine();
String [] str =line.trim().split(" ");
int n=str.length;
columns=n;
for(int i=0;i<n;i++)
{
matrix[rows][i]=Integer.parseInt(str[i]);
}
rows++;
}
Runtime error is coming
Runtime error time: 0.14 memory: 321088 signal:-1
List, likeArrayListto store, at least while you're loading the data. You can convert it to an array later with thetoArraymethod.