Matrix Program in Java

Matrix Program in Java
Matrix Program in Java
import java.util.*;

public class Matrix
{
    public static void main(String[] args)
    {
        int ar[][] = new int[3][3];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                System.out.print("Enter the number ar[" + i + "][" + j + "]:");
                ar[i][j] = sc.nextInt();
            }            
        }
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                System.out.print(ar[i][j]+" ");
            }
            System.out.println();
        }
        
    }
}

Output:

run:
Enter the number ar[0][0]:4
Enter the number ar[0][1]:5
Enter the number ar[0][2]:6
Enter the number ar[1][0]:3
Enter the number ar[1][1]:2
Enter the number ar[1][2]:1
Enter the number ar[2][0]:7
Enter the number ar[2][1]:8
Enter the number ar[2][2]:9
4 5 6 
3 2 1 
7 8 9 
java java tutorials learn java study java
Recent Posts