Simple Matrix
package com.talent;
import java.util.Scanner;
public class Matrix1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the no. of rows");
int row=sc.nextInt();
System.out.println("enter the no. of columns");
int column=sc.nextInt();
//now define 2D array to hold the matirx
int[][]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]=sc.nextInt();
}
}
System.out.println("MATRIX IS : ");
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
System.out.print(matrix[i][j]+"\t");
}
System.out.println();
}
}
}
OutPut->enter the no. of rows
3
enter the no. of columns
2
enter the data
4
5
6
7
8
9
MATRIX IS :
4 5
6 7
8 9
package com.talent;
import java.util.Scanner;
public class Matrix1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the no. of rows");
int row=sc.nextInt();
System.out.println("enter the no. of columns");
int column=sc.nextInt();
//now define 2D array to hold the matirx
int[][]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]=sc.nextInt();
}
}
System.out.println("MATRIX IS : ");
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
System.out.print(matrix[i][j]+"\t");
}
System.out.println();
}
}
}
OutPut->enter the no. of rows
3
enter the no. of columns
2
enter the data
4
5
6
7
8
9
MATRIX IS :
4 5
6 7
8 9
No comments:
Post a Comment