✔ 最佳答案
from java(1), you should understand it first before move to this one....
this one require using Math.(methods)
2012-10-15 14:25:48 補充:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class QuadraticCalculator {
public static void main (String[] arg){
try{
System.out.println("Welcome to use Quadratic Calculator");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the value of a:");
double a = Double.parseDouble(br.readLine());
System.out.println("Please enter the value of b:");
double b = Double.parseDouble(br.readLine());
System.out.println("Please enter the value of c:");
double c = Double.parseDouble(br.readLine());
if (a==0){System.out.println("a can't be zero!!!!,start the program again! :-P"); System.exit(0);}
double part1 = Math.pow(b,2)-4*a*c;
double ans1 = (-b+Math.sqrt(part1))/(2*a);
double ans2 = (-b-Math.sqrt(part1))/(2*a);
System.out.println("x1 = "+ans1);
System.out.println("x2 = "+ans2);
}
catch (IOException e){System.out.println("Please insert value!!!");}
}
}
2012-10-15 17:34:09 補充:
double = decimal points.... :D