Write a Java program that prints all real solutions to the quadratic equation ax2 + bx + c = 0. Read in a, b, cand use the quadratic formula. If the discriminant b2-4ac is negative, display a message stating that there are no real solutions. - Code

Latest

programs

Monday, October 10, 2011

Write a Java program that prints all real solutions to the quadratic equation ax2 + bx + c = 0. Read in a, b, cand use the quadratic formula. If the discriminant b2-4ac is negative, display a message stating that there are no real solutions.


Write a Java program that prints all real solutions to the quadratic equation ax2 + bx + c = 0. Read in a, b, cand use the quadratic formula. If the discriminant b2-4ac is negative, display a message stating that there are no real solutions.


import java.io.*;
import java.io.*;
class root
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a=Integer.parseInt(br.readLine());
int b=Integer.parseInt(br.readLine());
int c=Integer.parseInt(br.readLine());
int d=((b*b)-(4*a*c));
if(d>0)
{
System.out.print("roots are real and distinct");
}
if(d==0)
{
System.out.print("roots are real");
}
if(d<0)
{
System.out.print("there is no solution");
}
}

No comments:

Post a Comment