gpt4 book ai didi

java - BlueJ 中的常见错误,但尚未得到解决。与 括号相关

转载 作者:行者123 更新时间:2023-12-01 15:02:53 24 4
gpt4 key购买 nike

好吧,问题是括号很烦人。由于某种原因它似乎永远不起作用。我检查过其他网站,但这个问题没有得到解决。

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");
}
}

最佳答案

您缺少乘法运算符。

x1=(-b+sq)/2a;// Says "Please place ';' here"
x2=(-b-sq)/2a;//

应该是:(观察*)

  x1=((-b+sq)/(2*a);// Says "Please place ';' here"
x2=((-b-sq)/(2*a);//

关于java - BlueJ 中的常见错误,但尚未得到解决。与 括号相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13385792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com