Q-31- You can use Cramer’s rule to solve the following 2 X 2 system of linear equation:
ππ₯ + ππ¦ = π
ππ₯ + ππ¦ = π
x=(ππ − ππ) /(ππ − ππ) π¦ =(ππ − ππ)/ (ππ − ππ)
Write a java program that prompts the user to enter a, b, c, d, e, and f and displays the result. If (ad - bc) is 0, report that “The equation has no solution.”
INPUT :
import java.util.Scanner;
public class NCM {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double a ,b ,c ,d ,e ,f ;
double x , y ,z;
System.out.println("Enter The Value Of a ,b ,c ,d ,e ,f :");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
d=sc.nextDouble();
e=sc.nextDouble();
f=sc.nextDouble();
z=a*d-b*c;
x=(e*d-b*f)/z;
y=(a*f-e*c)/z;
if(z==0)
{
System.out.println("The Equation Has No Solution.");
}
else
{
System.out.println("x is "+x+" and y is "+y);
}
}
}
OUTPUT :
Enter The Value Of a ,b ,c ,d ,e ,f :
9.0 4.0 3.0 -5.0 -6.0 -21.0
x is -2.0 and y is 3.0
ππ₯ + ππ¦ = π
ππ₯ + ππ¦ = π
x=(ππ − ππ) /(ππ − ππ) π¦ =(ππ − ππ)/ (ππ − ππ)
Write a java program that prompts the user to enter a, b, c, d, e, and f and displays the result. If (ad - bc) is 0, report that “The equation has no solution.”
INPUT :
import java.util.Scanner;
public class NCM {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double a ,b ,c ,d ,e ,f ;
double x , y ,z;
System.out.println("Enter The Value Of a ,b ,c ,d ,e ,f :");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
d=sc.nextDouble();
e=sc.nextDouble();
f=sc.nextDouble();
z=a*d-b*c;
x=(e*d-b*f)/z;
y=(a*f-e*c)/z;
if(z==0)
{
System.out.println("The Equation Has No Solution.");
}
else
{
System.out.println("x is "+x+" and y is "+y);
}
}
}
Enter The Value Of a ,b ,c ,d ,e ,f :
9.0 4.0 3.0 -5.0 -6.0 -21.0
x is -2.0 and y is 3.0
Enter The Value Of a ,b ,c ,d ,e ,f :
1.0 2.0 2.0 4.0 4.0 5.0
The Equation Has No Solution.
No comments:
Post a Comment