PROGRAM :
import java.util.Scanner;
public class LinearEquation {
public static void main(String[] args) {
System.out.println("The linear equation is in the form: aX +bY+c = 0");
double a,b,c,a1,b1,c1,x,y;
System.out.println("Enter the value of first linear equation a:");
Scanner s= new Scanner(System.in);
a=s.nextDouble();
System.out.println("Enter the value of first linear equation b:");
b=s.nextDouble();
System.out.println("Enter the value of first linear equation c:");
c=s.nextDouble();
System.out.println("Enter the value of second linear equation a:");
a1=s.nextDouble();
System.out.println("Enter the value of first linear equation b:");
b1=s.nextDouble();
System.out.println("Enter the value of second linear equation c:");
c1=s.nextDouble();
if(a/a1 != b/b1)
{
x= (b*c1 - b1*c)/(a*b1 - a1*b);
y= (c*a1 - c1*a)/ (a*b1 - a1*b);
System.out.println("UNIQUE SOLUTION and INTERSECT ALSO");
System.out.println("values of x : "+x );
System.out.println("values of y : "+y );
}
else if (a/a1==b/b1 && b/b1==c/c1)
{
System.out.println("infinitely many solutions");
}
else if (a/a1==b/b1 && b/b1!=c/c1)
{
System.out.println("no solutions");
}
}
}
OUTPUT :
The linear equation is in the form: aX +bY+c = 0
Enter the value of first linear equation a:
9
Enter the value of first linear equation b:
6
Enter the value of first linear equation c:
3
Enter the value of second linear equation a:
5
Enter the value of first linear equation b:
4
Enter the value of second linear equation c:
9
UNIQUE SOLUTION and INTERSECT ALSO
values of x : 7.0
values of y : -11.0
No comments:
Post a Comment