2D Array || two dimensional array in java language.
import java.util.*;
public class Array{
public static void main(String[] args) {
int row,col;
Scanner sc=new Scanner(System.in);
System.out.println("enter the size of rows=");
row=sc.nextInt();
System.out.print("enter the size of columns=");
col=sc.nextInt();
int number[][]=new int[row][col];
System.out.println("enter the numbers=");
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
number[i][j]=sc.nextInt();
}
System.out.println();
}
System.out.println("array is=");
for(int i=0; i<row ; i++ ){
for(int j=0; j<col; j++){
System.out.print(number[i][j]+" ");
}
System.out.println();
}
}
}
■》output->
enter the size of rows= 2
enter the size of columns=3
enter the numbers=
1
2
3
4
5
6
array is=
1 2 3
4 5 6
Comments
Post a Comment