Home » Sometech » WAP in Java that prints all real solutions to the Quadratic eqyation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula.

WAP in Java that prints all real solutions to the Quadratic eqyation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula.

Java Coding

import java.util.Scanner;

class quardatic

{

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:”+x+” “+y);

}

}

}

 

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: