Quadratic

0

java

목록 보기
8/11
post-thumbnail

import acm.program.*;

public class Quadratic extends ConsoleProgram {
public void run() {
/ You fill this in /
showMessage();
findsolution();

}
	
private void showMessage() {
      println("Enter coefficients for the quadratic equation:");
}

private void findsolution() {

      int a = readInt("Enter a: ");
      int b = readInt("Enter b: ");
      int c = readInt("Enter c: ");
      double x1 = (-b + Math.sqrt(b*b-4*a*c))/(2*a);
      double x2 = (-b - Math.sqrt(b*b-4*a*c))/(2*a);
      println("The first solution is " + x1 + ".");
      println("The second solution is " + x2 + ".");
      
}

}

profile
초보 데이터분석가의 기록 공간입니다 😁

0개의 댓글