tgoop.com/java_codings/68
Last Update:
48. Create & Display Matrix.
import java.util.Scanner;
class Matrix_Create {
Scanner scan;
int matrix[][];
int row, column;
void create() {
scan = new Scanner(System.in);
System.out.println("Matrix Creation");
System.out.println("\nEnter number of rows :");
row = Integer.parseInt(scan.nextLine());
System.out.println("Enter number of columns :");
column = Integer.parseInt(scan.nextLine());
matrix = new int[row][column];
System.out.println("Enter the data :");
for(int i=0; i<row ; i++) {
for(int j=0; j
<column ; j++) {
matrix[i][j] =scan.nextInt();
}
}
}
void display() {
System.out.println("\nThe Matrix is :");
for(int i=0; i <row ; i++) {
for(int j=0; j <column ; j++) {
System.out.print("\t" + matrix[i][j]);
}
System.out.println();
}
}
}
class CreateAndDisplayMatrix {
public static void main(String
args[]) {
Matrix_Create obj=new Matrix_Create();
obj.create();
obj.display();
}
}
@java_codings
BY Advance Java π¨βπ»
Share with your friend now:
tgoop.com/java_codings/68