โดย SleEpingDogs » 11/01/2012 10:00 am
ข้อ 1) import java.util.Scanner;
public class Find_x {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
System.out.println("Input a : ");
String vala =in.nextLine();
System.out.println("Input b : ");
String valb =in.nextLine();
System.out.println("Input c : ");
String valc =in.nextLine();
int a = Integer.parseInt(vala); /**a = 1 **/
int b = Integer.parseInt(valb); /**b = -6 **/
int c = Integer.parseInt(valc); /**c = 8 **/
//System.out.println("The algorithm is " + a + "x*x + " + b + "x + " + c + " = 0");
doCalculate(a, b, c);
}
public static void doCalculate(int a, int b, int c){
double Root = Math.sqrt(b*b - (4*a*c));
double valplus = ((-b) + Root)/(2*a);
double valminus = ((-b) - Root)/(2*a);
System.out.println("The value of x is " + valplus);
System.out.println("The value of x is " + valminus);
}
}
อย่างนี้ สมบูรณ์หรือยังครับ หรือต้องแก้ไขตรงไหนบ้าง???
ข้อ 1) import java.util.Scanner;
public class Find_x {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
System.out.println("Input a : ");
String vala =in.nextLine();
System.out.println("Input b : ");
String valb =in.nextLine();
System.out.println("Input c : ");
String valc =in.nextLine();
int a = Integer.parseInt(vala); /**a = 1 **/
int b = Integer.parseInt(valb); /**b = -6 **/
int c = Integer.parseInt(valc); /**c = 8 **/
//System.out.println("The algorithm is " + a + "x*x + " + b + "x + " + c + " = 0");
doCalculate(a, b, c);
}
public static void doCalculate(int a, int b, int c){
double Root = Math.sqrt(b*b - (4*a*c));
double valplus = ((-b) + Root)/(2*a);
double valminus = ((-b) - Root)/(2*a);
System.out.println("The value of x is " + valplus);
System.out.println("The value of x is " + valminus);
}
}
อย่างนี้ สมบูรณ์หรือยังครับ หรือต้องแก้ไขตรงไหนบ้าง???