To learn use of in case of a two dimensional array.
To learn use of in case of a two dimensional array.
Program:
import java.util.Scanner;
public class TwoDimArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows :");
int r = sc.nextInt();
System.out.print("Enter number of columns :");
int c = sc.nextInt();
System.out.print("Enter elements of array :");
int arr[][] = new int[r][c];
for (int i = 0; i < arr.length; i++)//used length case {
for (int j = 0; j < c; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println("Entered elements of array are:");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < c; j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}
Post a Comment