구문 오류 ";"줄에 "double a, b, c, discriminant, root;"가 필요합니다.오류 ";",, 변수 선언 후 예상 됨
어떻게이 오류를 해결할 수 있습니까?
public class Quadratic {
double a, b, c, discriminant, root;
discriminant = (b * b) - 4 * a * c;
public Quadratic(double a, double b, double c) {
}
public String calculateroots() {
if (discriminant >= 0){
root = Math.sqrt(discriminant)/(2 * a);
System.out.println("Your roots are " + (-1 * b) + "+" + root + "and" + (-1 * b) + (-1 * root) +".");
}
else {
root = Math.sqrt(Math.abs(discriminant))/(2 * a);
System.out.println("Your roots are " + (-1 * b) + "+ i" + root + "and" + (-1 * b) + "i" + (-1 * root) +".");
}
}
}
해당 코드에는 몇 가지 문제가 있습니다. 다음으로 시작 : discriminant = (b * b) - 4 * a * c; 메서드 또는 초기화 블록에 있어야합니다. – Stultuske
힌트 : Java 명명 규칙을 읽어보십시오. 방법 이름은 낙타로 바뀝니다! 그런 다음 java 구문에 대해 읽어보십시오. 당신은 그들이 맞는 것 같아요 진술을 넣을 수 없다 ... – GhostCat
나는 생성자에서 인스턴스 변수를 설정하고 그곳에서 판별자를 해결하는 것이 좋습니다. 'public 2 차 방정식 (double a, double b, double c) {this.a = a; this.b = b; this.c = c; 판별 자 = (b * b) -4 * a * c; }' – Orin