- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverse2D.java
More file actions
Latest commit
41 lines (41 loc) · 746 Bytes
/
Copy pathreverse2D.java
File metadata and controls
41 lines (41 loc) · 746 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
36
37
38
39
40
41
importjava.util.Scanner;
classreverse2D
{
publicstaticvoidmain(Stringargs[])
{
intk=0,i,j;
Scannersc = newScanner(System.in);
intn = sc.nextInt();
int[] arr1 = newint[n];
int[][] arr2 = newint[2][2];
for(i=0;i<n;i++)
{
arr1[i] = sc.nextInt();
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
arr2[i][j]=arr1[k++];
}
}
System.out.println("The given array is:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
System.out.println("The reverse of the array is:");
for(i=1;i>=0;i--)
{
for(j=1;j>=0;j--)
{
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
}
}