Repository navigation
Expand file tree
/
Copy pathmatrice_calculator.java
More file actions
69 lines (69 loc) · 2.09 KB
/
Copy pathmatrice_calculator.java
File metadata and controls
69 lines (69 loc) · 2.09 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
import java.util.Scanner;
class matrices{
public static void main(String[] args){
Scanner sushi=new Scanner(System.in);
System.out.println("1(addition) 2(subtraction) 3(multiplication)");
int choice=sushi.nextInt();
if (choice==1||choice==2){
System.out.println(" #of rows and colums");
int rc=sushi.nextInt();
int[][] jeremy=new int[rc][rc];
int[][] ethan=new int[rc][rc];
for(int x=0;x<rc;x++){
for (int y=0;y<rc;y++){
System.out.println(" what would u like the number in the "+x+" column and "+y+" row then the number of the same position in yoursecond matrix");
int numb=sushi.nextInt();
jeremy[x][y]=numb;
int numb2=sushi.nextInt();
ethan[x][y]=numb2;
}
}
int[][] end=new int[rc][rc];
for(int x=0;x<rc;x++){
for (int y=0;y<rc;y++){
if (choice==1){
end[x][y]=jeremy[x][y]+ethan[x][y];}
else{
end[x][y]=jeremy[x][y]-ethan[x][y];}
}
}
}
else{
System.out.println(" #of rows and colums");
int r=sushi.nextInt();
int c=sushi.nextInt();
int[][] jeremy=new int[c][r];
int[][] ethan=new int[r][c];
for(int x=0;x<c;x++){
for (int y=0;y<r;y++){
System.out.println(" what would u like the number in the "+x+" column and "+y+" row");
int numb=sushi.nextInt();
jeremy[x][y]=numb;
}
}
for(int x=0;x<r;x++){
for (int y=0;y<c;y++){
System.out.println(" what would u like the number in the "+x+" column and "+y+" row of the second matrix to be");
int numb=sushi.nextInt();
ethan[x][y]=numb;
}
}
int[][] end=new int[r][r];
for(int x=0;x<r;x++){
for (int y=0;y<r;y++){
int sum=0;
for (int p=0;p<c;p++){
sum+=jeremy[p][x]*ethan[y][p];
}
end[y][x]=sum;
}
}
}
for (int x=0;x<end.length;x++){
for (int y=0;y<end[0].length;y++){
System.out.print(end[y][x]);
}
System.out.println;
}
}
}