Posted by : Unknown Friday, 26 June 2015



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, 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:"+x+" 
"+y);                                
                } 
        } 
}


Output:

Enter the values of a, b, c:
5
5
2
No real roots

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Translate

Popular Post

Total Pageviews

Blog Archive

- Copyright © Learning Java Program - Powered by Blogger -