-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMatrixSwap.java
More file actions
73 lines (70 loc) · 2.25 KB
/
ArrayMatrixSwap.java
File metadata and controls
73 lines (70 loc) · 2.25 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class ArrayMatrixSwap {
public static void main(String args[]){
Scanner a=new Scanner(System.in);
int Array[][]=new int[100][100];
int temp[]=new int[100];
System.out.print("Enter a size of row in Matrix :- ");
int n=a.nextInt();
System.out.print("Enter a size of column in Matrix :- ");
int m=a.nextInt();
System.out.println("Enter a Element in Matrix :- ");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
Array[i][j]=a.nextInt();
}
}
System.out.println("Display a Original Matrix :- ");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
System.out.print(Array[i][j]+" ");
}
System.out.println("");
}
int choice;
System.out.println("Enter your choice to change a Matrix :- ");
System.out.println("1. Row\n2. Coloum");
System.out.print("Choice :-");
choice=a.nextInt();
if(choice==1){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i==1){
temp[j]=Array[i][j];
Array[i][j]=Array[n][j];
Array[n][j]=temp[j];
}
}
}
System.out.println("Display a Swapped Matrix in row :- ");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
System.out.print(Array[i][j]+" ");
}
System.out.println("");
}
}
else if(choice==2){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(j==1){
temp[i]=Array[i][j];
Array[i][j]=Array[i][m];
Array[i][m]=temp[i];
}
}
}
System.out.println("Display a Swapped Matrix in Column :- ");
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
System.out.print(Array[i][j]+" ");
}
System.out.println("");
}
}
else{
System.out.println("please Enter a valid value .");
}
a.close();
}
}