Wednesday, May 1, 2019

Write a java program that display the roots of a quadratic equation ax2+bx=0. Calculate the discriminate D and basing on value of D, describe the nature of root


PROGRAM:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Quadratic
{
          public static void main(String x[]) throws IOException
          {
                   int a,b,c,d;
BufferedReader br=new BufferedReader(new  InputStreamReader(System.in));
                   System.out.println("Enter xsquare coefficient: ");
                   a=Integer.parseInt(br.readLine());
                   System.out.println("Enter x coefficient : ");
                   b=Integer.parseInt(br.readLine());
                   c=-b/a;
                   System.out.println("\nRoots are 0 and "+c+"\n");
                   d=b*b;
                   System.out.println("\nRoots are real and distinct with discriminant : "+d);
                  
          }
}

Output:



No comments:

Post a Comment