-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.java
More file actions
38 lines (38 loc) · 1.76 KB
/
Matrix.java
File metadata and controls
38 lines (38 loc) · 1.76 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
import java.util.*;
class Matrix{
Scanner sc=new Scanner(System.in);
int ans;
int[][] matrix=new int[2][2];
void getData(){
System.out.println("Enter the first number");
matrix[0][0]=sc.nextInt();
System.out.println("Enter the second number");
matrix[0][1]=sc.nextInt();
System.out.println("Enter the third number");
matrix[1][0]=sc.nextInt();
System.out.println("Enter the fourth number");
matrix[1][1]=sc.nextInt();
}
void processData(){
if ((matrix[0][0]>matrix[0][1])&&(matrix[0][0]>matrix[1][0])&&(matrix[0][0]>matrix[1][1]))
ans=matrix[0][0];
else if ((matrix[0][1]>matrix[0][0])&&(matrix[0][1]>matrix[1][1])&&(matrix[0][1]>matrix[1][0]))
ans=matrix[0][1];
else if ((matrix[1][0]>matrix[0][0])&&(matrix[1][0]>matrix[0][1])&&(matrix[1][0]>matrix[1][1]))
ans=matrix[1][0];
else if ((matrix[1][1]>matrix[0][0])&&(matrix[1][1]>matrix[0][1])&&(matrix[1][1]>matrix[1][0]))
ans=matrix[1][1];
else if ((matrix[0][0]==matrix[0][1])||(matrix[0][0]==matrix[1][0])||(matrix[0][0]==matrix[1][1])||(matrix[0][1]==matrix[0][0])||(matrix[0][1]==matrix[1][1])||(matrix[0][1]==matrix[1][0])||(matrix[1][0]==matrix[0][0])||(matrix[1][0]==matrix[0][1])||(matrix[1][0]==matrix[1][1])||(matrix[1][1]==matrix[0][0])||(matrix[1][1]==matrix[0][1])||(matrix[1][1]==matrix[1][0])){
System.out.println("Function Unavailable");
System.exit(0);
}
System.out.println("|"+"\t"+matrix[0][0]+" \t"+matrix[0][1]+"\t|\n|"+"\t"+matrix[1][0]+" \t"+matrix[1][1]+"\t|");
System.out.println("The greatest Number is"+" "+ans);
}
public static void main(String[] args){
Matrix m=new Matrix();
System.out.println("This application asks the user for 4 numbers and then finds the greatest number");
m.getData();
m.processData();
}
}