唔識做呢題java programming(2)

2012-10-14 8:43 pm
唔識做呢題java programming

請根據下面張圖寫個java code比我! thx


http://i987.photobucket.com/albums/ae355/delaynopemore/2-15.jpg

回答 (2)

2012-10-15 10:25 pm
✔ 最佳答案
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
參考: hope you got it :-)
2012-10-15 2:17 am


收錄日期: 2021-04-23 19:38:39
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20121014000051KK00230

檢視 Wayback Machine 備份