public class ExceptionDemo {
public static void main(String[] args){
try{
double a = Double.parseDouble(args[0]);
double b =
Double.parseDouble(args[1]);
double c = Double.parseDouble(args[2]);
double x = (-b + Math.sqrt(b*b-4*a*c))/(2*a);
System.out.print("x =
"+x);
x = (-b - Math.sqrt(b*b-4*a*c)) / (2*a);
System.out.println(" or x = "+x);
}catch(ArithmeticException ex){
System.out.println(ex.toString());
}catch(NumberFormatException
ex){
System.out.println("Invalid Numeric format");
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น