Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear.java
More file actions
Latest commit
170 lines (146 loc) · 4.75 KB
/
Copy pathLinear.java
File metadata and controls
170 lines (146 loc) · 4.75 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
importjava.util.Scanner;
publicclassLinear {
publicstaticvoidmain(String[] args)
{
Scanners=newScanner(System.in);
System.out.println("1. (1×1) Matrix\t 2. (2×2) Matrix\t3. (3×3) Matrix");
System.out.println(" ");
System.out.print("Select your choice: ");
intn=s.nextInt();
switch(n)
{
case1:
if (n==1)
{
Scannersc=newScanner(System.in);
System.out.print("Enter a value: ");
doublea=sc.nextDouble();
System.out.print("Enter b value: ");
doubleb=sc.nextDouble();
System.out.print("Enter c value: ");
doublec=sc.nextDouble();
System.out.println("Equation is:"+a+"x"+"+"+b+"y"+"="+c);
System.out.println("1.Find x value\t2.Find y value\t3.Default");
System.out.print("Select your choice: ");
intv=sc.nextInt();
switch(v)
{
case1:
if(v==1)
{
if(b>=0)
{
System.out.print(" y value: ");
doubley=sc.nextDouble();
doublex=(c-(b*y))/a;
System.out.println("Equation is:"+a+"x"+"+"+b+"*"+y+"="+c);
System.out.print("x= "+x);
}
}
break;
case2:
if(v==2)
{
if(a>=0)
{
System.out.print(" x value: ");
doublex=sc.nextDouble();
doubley=(c-(a*x))/b;
System.out.println("Equation is:"+a+"*"+x+"+"+b+"y" +"="+c);
System.out.print("y= "+y);
}
}
break;
case3:
System.out.println("Default");
break;
} }
break;
case2:
if(n==2)
{
System.out.println(" ");
Scannersc=newScanner(System.in);
System.out.print("Enter the a value: ");
doublea=sc.nextInt();
System.out.print("Enter the b value: ");
doubleb=sc.nextInt();
System.out.print("Enter the c value: ");
doublec=sc.nextInt();
System.out.println(" ");
System.out.print("Enter the d value: ");
doubled=sc.nextInt();
System.out.print("Enter the e value: ");
doublee=sc.nextInt();
System.out.print("Enter the f value: ");
doublef=sc.nextInt();
System.out.println();
System.out.println("The first Equation "+a +"x+" +b +"y" +"="+c);
System.out.println();
System.out.println("The second Equation "+d +"x+" +e +"y" +”="+f);
if((a*d-(b*c)!=0))
{
double x=(e*c)-(b*f)/(a*e-b*d);
double y=(a*f)-(d*c)/(a*e)-(b*d);
System.out.println();
System.out.println("xvalue: "+x);
System.out.println();
System.out.println("yvalue: "+y);
}
}
else
{
System.out.println("NoSolution");
}
break;
case 3:
if(n==3)
{
System.out.println(" ");
Scannersc=newScanner(System.in);
System.out.print("Enter the a1 value: ");
doublea1=sc.nextInt();
System.out.print("Enter the b1 value: ");
doubleb1=sc.nextInt();
System.out.print("Enter the c1 value: ");
doublec1=sc.nextInt();
System.out.print("Enter the d1 value: ");
doubled1=sc.nextInt();
System.out.println(" ");
System.out.print("Enter the a2 value: ");
doublea2=sc.nextInt();
System.out.print("Enter the b2 value: ");
doubleb2=sc.nextInt();
System.out.print("Enter the c2 value: ");
doublec2=sc.nextInt();
System.out.print("Enter the d2 value: ");
doubled2=sc.nextInt();
System.out.println(" ");
System.out.print("Enter the a3 value: ");
doublea3=sc.nextInt();
System.out.print("Enter the b3 value: ");
doubleb3=sc.nextInt();
System.out.print("Enter the c3 value: ");
doublec3=sc.nextInt();
System.out.print("Enter the d3 value: ");
doubled3=sc.nextInt();
System.out.println("The first Equation "+a1 +"x+" +b1 +"y+"+c2 +"z" +"="+d1);
System.out.println("The Second Equation "+a2 +"x+" +b2 +"y+"+c3 +"z" +"="+d2);
System.out.println("The Third Equation "+a3 +"x+" +b3 +"y+"+c3 +"z" +"="+d3);
doublen1=( ((d1*b2)-(b1*d2)) + ((b1*c2)-(c1*b2))+ ((d2*b3)-(b2*d3)+ ((b2*c3)-(c2*b3))));
doublen2=( ((a1*b2)-(b1*d2)) + ((b1*c2)-(c1*b2))+ ((a2*b3)-(b2*a3)+ ((b2*c3)-(c2*b3))));
doublex=(n1/n2);
doublem1=( ((a1*d2)-(d1*a2)) + ((d1*c2)-(c1*d2))+ ((a2*d3)-(d2*a3)+ ((d2*c3)-(c2*d3))));
doublem2=( ((a1*b2)-(b1*d2)) + ((b1*c2)-(c1*b2))+ ((a2*b3)-(b2*a3)+ ((b2*c3)-(c2*b3))));
doubley=(m1/m2);
doublel1=( ((a1*b2)-(b1*d2)) + ((b1*d2)-(d1*b2))+ ((a2*b3)-(b2*a3)+ ((b2*d3)-(d2*b3))));
doublel2=( ((a1*b2)-(b1*d2)) + ((b1*c2)-(c1*b2))+ ((a2*b3)-(b2*a3)+ ((b2*c3)-(c2*b3))));
doublez=(l1/l2);
System.out.println("x: "+x);
System.out.println("y: “+y);
System.out.println("z: "+z);
break;
}
}
}
}