好的,所以问题在于括号很烦人。由于某种原因,它似乎永远不会起作用。我在其他网站上检查过,但这并没有得到解决。
import java.util.Scanner;
class x14
{
int a;
int b;
int c;
double b2 = Math.pow(b,2);
double sq = Math.sqrt(b2 - 4*a*c);
public void main()
{
Scanner input = new Scanner(System.in);
System.out.println("Please input 'a'");
a = input.nextInt();
System.out.println("Please input 'b'");
b = input.nextInt();
System.out.println("Please input 'c'");
c = input.nextInt();
System.out.println("Thank you!");
double x1 = 0.0;
double x2 = 0.0;
x1=(-b+sq)/2a;// Says "Please place ';' here"
x2=(-b-sq)/2a;// Says "Please place ';' here"
/* When I Try this : ((-b+sq)/2a);
* It says i have to place ')' at the end.
*/
System.out.println("Equation x1 : " + x1);
System.out.println("Equation x2 : " + x2);
if(sq > 0)
System.out.println("The Roots are Real and unequal");
else if(sq == 0)
System.out.println("The Roots are Real and Equal");
else if(sq < 0)
System.out.println("The Roots are imaginary");
}
}