Btechadda.com

test

by Shivu on May.28, 2010, under Uncategorized

To write a java program that prints all real solutions of the expression ax2+bx+c=0.

Program:

import java.io.*;
class Qexp
 {
	  public static void main(String arg[])
	   {
			double a=5,b=2,c=3;
			double d,x1,x2;
			d=b*b-4*a*c;
			if(d<0)
			 {
				System.out.println("Roots are imaginary");
			 }
			else
			 {
				  x1=(-b+Math.sqrt(d))/(2*a);
				  x2=(-b-Math.sqrt(d))/(2*a);
				  System.out.println("x1=" + x1 + " x2=" + x2);
			 }
	   }
 }

Input & Output Analysis:-

Roots are imaginary

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...