package nameyu;import java.util.Scanner; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner (System.in); System.out.print("Enter a,b,c:"); double a=input.nextDouble(); double b=input.nextDouble(); double c=input.nextDouble(); double r1,r2; if(Math.pow(b, 2)-4*a*c>0){ r1=((-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5))/2*a; r2=((-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5))/2*a; System.out.println("The equation has two roots"+r1+" and "+r2); } else if (Math.pow(b, 2)-4*a*c==0){ r1=r2=(-b)/2*a; System.out.println("The equation has one root "+r1); } else if (Math.pow(b, 2)-4*a*c<0){ System.out.println("The equation has no real roots"); }
} }
|