// 실습 2차 방정식의 계수 입력받아, 근을 출력 Math.sqrt()
public class Test001 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c, D;
System.out.print("2차 방정식 계수(a, b, c) 입력 : ");
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
D = b*b - 4*a*c; // 판별식
if (D<0)
System.out.println("근이 없음");
else if (D==0)
System.out.printf("중근 = %.1f\n", -b/(2.0*a) );
else
System.out.printf("두 실근 = %.1f, %.1f\n", (-b+Math.sqrt(D))/(2.0*a), (-b-Math.sqrt(D))/(2.0*a) );
}
}
댓글 없음:
댓글 쓰기