/* Java program to print all real solutions to the
qudratic eq ax2+bx+c=0 Read a,b,c values
and use the formula (–b+sqrt(b2-4ac))/2a with command-line arguments*/
// File Name: roots.java
import java.io.*;
import java.lang.Math;
class roots{
public static void main(String args[])throws IOException{
int a,b,c,d;
double r1,r2;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);
d=((b*b)-(4*a*c));
if(d<0){
System.err.println("No Real Roots For The Inputed Values..");
System.out.println("www.shashanktechnologies.blogspot.com");
}
else{
r1=((-b)+Math.sqrt(d))/(2*a);
r2=((-b)-Math.sqrt(d))/(2*a);
System.out.println("Root 1:"+r1);
System.out.println("Root 2:"+r2);
System.out.println("www.shashanktechnologies.blogspot.com");
}
}
}
OUTPUT:
COMPILATION: G:\shashank>javac roots.java
INTERPRETATION: G:\shashank>java roots 1 3 2
No comments:
Post a Comment