My college professor told me to make a program that calculates if two lines are parallel or not using the equation a1b2=a2b1 and If they are parallel it will print the lines are parallel but if they are not I have to use the equation (𝑥𝑖,𝑦𝑖)=(𝑏1𝑐2−𝑏2𝑐1/𝑎1𝑏2−𝑎2𝑏1 , 𝑐1𝑎2−𝑐2𝑎1/𝑎1𝑏2−𝑎2𝑏1) to find the intersection but I get this error The local variable x may not have been initialized and I don't know how to solve It My questions are
1- Why did I get this error?
2- Did I typed the equations wrong In my code?
3- Is there a better way to write this program?
4- How to find which quadrant the lines lie?
Scanner input = new Scanner(System.in);
double a1 , b1 , c1 , a2 , b2 , c2, X ,Y;
System.out.print("enter line 1 coefficient");
a1 = input.nextDouble();
b2 = input.nextDouble();
c1 = input.nextDouble();
System.out.print("enter line 2 coefficient");
a2 = input.nextDouble();
b1 = input.nextDouble();
c2 = input.nextDouble();
if (a1 * b2 == a2 * b1)
System.out.print("the lines are parallel");
else if (a1 * b2 != a2 * b1)
X = ((b1*c2) - (b2*c1) /(a1*b2) - (a2*b1));
Y = ((c1*a2) - (c2*a1) / (a1*b2) - (a2*b1));
System.out.printf( "intersected straight lines in point %.2f , %.2f that lies in first quadrant" , X ,Y);
Aucun commentaire:
Enregistrer un commentaire