1. JAVA WEEK1(A)
/*
Week1 : a) Write a Java program that prints all real solutions to the quadratic
equation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the
discriminant b2 -4ac is negative, display a message stating that there are no real
solutions. */
public class Quadratic
{
public static void main(String args[])
{
double a,b,c,root1,root2;
a=3.0;
b=4.0;
c=2.0;
if((b*b-4*a*c)==0)
{
System.out.println("n ROOTS ARE EQUAL");
root1=-b/(2*a);
System.out.println("n root "+root1);
}
if((b*b-4*a*c) > 0)
{
root1=-b+Math.sqrt(b*b-4*a*c)/(2*a);
root2=-b-Math.sqrt(b*b-4*a*c)/(2*a);
System.out.println("nROOTS ARE REAL:n");
System.out.println("n root1 "+root1+"n root2 "+root2);
}
else
System.out.println("n Imaginary Roots.");
}
} // End of Class
Page 1