-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixOperation.java
96 lines (83 loc) · 1.82 KB
/
MatrixOperation.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.Scanner;
public class MatrixOperation {
static void MatrixAddition(){
System.out.println("Matrix Addition");
Scanner input =new Scanner(System.in);
int rows,coloums;
System.out.print("Rows: ");
rows=input.nextInt();
System.out.println("");
System.out.print("Coloums: ");
coloums=input.nextInt();
int size=rows*coloums;
double[][]matrix= new double [rows][coloums];
//getting the first matrix
System.out.printf("Enter your matrix: ");
for(int i=0;i<rows;i++)
{
for(int j=0;j<coloums;j++)
{
int arrayElement;
arrayElement= input.nextInt();
matrix [i][j]=arrayElement;
}
}
//Printing the matrix 1
System.out.printf("[ ");
for(int i=0;i<rows;i++)
{
System.out.printf("[ ");
for(int j=0;j<coloums;j++)
{
double value=matrix[i][j];
if(j==coloums-1)
{
System.out.printf(" %f ",value);
}
else
{
System.out.printf(" %f , ",value);
}
}
if(i==rows-1)
{
System.out.printf(" ]");
}
else
{
System.out.printf(" ],");
}
}
System.out.printf(" ]");
//2nd Matrix
}
static void MatrixSubtraction() {
System.out.println("Matrix Subtraction");
}
static void MatrixMultiplication() {
System.out.println("Matrix Multiplication");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int decision;
do
{
System.out.println("Choose your matrix operation below: ");
System.out.println("1-)Matrix addition\n2-)Matrix Subtraction\n3-)Matrix Multiplication\4-)Scalar Multiplication");
System.out.print("Operation: ");
decision=input.nextInt();
}while(decision<0 || decision>4);
if(decision==1)
{
MatrixAddition();
}
if(decision==2)
{
MatrixSubtraction();
}
if(decision==3)
{
MatrixMultiplication();
}
}
}