/* 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 */
// File Name: roots.java
import java.io.*;
import java.lang.Math;
class roots {
public static void main(String args[]) throws IOException {
String s;
int a,b,c,d;
double r1,r2;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter a value");
s=in.readLine();
a=Integer.parseInt(s);
System.out.println("Enter b value");
s=in.readLine();
b=Integer.parseInt(s);
System.out.println("Enter c value");
s=in.readLine();
c=Integer.parseInt(s);
d=((b*b)-(4*a*c)); if(d<0)
{
System.out.println("www.shashanktechnologies.blogspot.com");
System.err.println("No real solution...");
}
else
{
r1=((-b)+Math.sqrt(d))/(2*a);
r2=((-b)-Math.sqrt(d))/(2*a);
System.out.println("Roots Of Given Equation "+a+"x2+"+b+"x+"+c+" Are "+r1+" & "+r2);
System.out.println("www.shashanktechnologies.blogspot.com");
}
}
}
OUTPUT:
COMPILATION: G:\shashank>javac roots.java
INTERPRETATION: G:\shashank>java roots
No comments:
Post a Comment