Type Here to Get Search Results !

Write a java program for display the roots of quadratic equation ax2+bx+c=0

 import java.util.Scanner;

class solutions

{

public static void main(String[] args) 

int a,b,c; 

double x,y; 

Scanner s=new Scanner(System.in); 

System.out.println("Enter the values of a,b, and c"); 

a=s.nextInt(); 

b=s.nextInt(); 

c=s.nextInt(); 

int k=(b*b)-4*a*c; 

if(k<0) 

System.out.println("No real roots"); 

else 

double l=Math.sqrt(k); 

x=(-b-l)/2*a; 

y=(-b+l)/2*a; 

System.out.println("Roots of given equation:\n"+"X Value is:"+x+"\nY Value  is:"+y); 


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M