-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupperdiagonal.java
More file actions
35 lines (35 loc) · 956 Bytes
/
upperdiagonal.java
File metadata and controls
35 lines (35 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
public class upperdiagonal
{
public static void main(String[]args)
{
Scanner ob = new Scanner(System.in);
int[][]a;
int i,j;
System.out.print("Enter the Size of The Square Matrix:");
int n=ob.nextInt();
a=new int[n][n];
System.out.println("Enter the Numbers in the Array:");
for(i=0;i<n;i++)
{
System.out.println("Row:"+(i+1));
for(j=0;j<n;j++)
a[i][j]=ob.nextInt();
}
System.out.println("The Array:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
System.out.println("The Upper Diagonal:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if((i+j)<n)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
}