(I am not able to get the error )
May I know whether the reading of an each array element is correct?
import java.util.Scanner;
public class Twodarrayops
{
static Scanner scn=new Scanner(System.in);
public static void main(String[] args)
{
int [][] array=takeinput();
display(array);
}
private static int[][] takeinput()
{
System.out.println("Enter the number of rows ");
int rows=scn.nextInt();
System.out.println("Enter the number of columns ");
int columns=scn.nextInt();
int[][] arr=new int[rows][columns];
System.out.println("Enter the array elements ");
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
arr[rows][columns]=scn.nextInt();
}
System.out.println();
}
return arr;
}
private static void display(int[][] arr)
{
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr[i].length;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
}