import java.util.Scanner;
class larry{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,c,d,e;
while(sc.hasNext()){
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if ( Math.pow(b,2) - 4*a*c >0){
d=(Math.sqrt(b*b-4*a*c))/(2*a);
e=(-Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println("Two different roots x1="+d+"x2="+e);
}
else if (Math.pow(b,2)-4*a*c=0){
System.out.println("Two same roots");
}
else
System.out.println( "No real root");
}
}
}
import java.util.Scanner;
class larry{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,c,d,e;
while(sc.hasNext()){
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if ( Math.pow(b,2) - 4*a*c >0){
d=(Math.sqrt(b*b-4*a*c))/(2*a);
e=(-Math.sqrt(b*b-4*a*c))/(2*a);
System.out.println("Two different roots x1="+d+"x2="+e);
}
else if (Math.pow(b,2)-4*a*c=0){
System.out.println("Two same roots");
}
else
System.out.println( "No real root");
}
}
}
後來在網路上查完改寫的~~可是感覺很多多於步驟...
import java.util.Scanner;
class larry{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,c;
double T;
int A,d,e;
while(sc.hasNext()){
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
T=Math.sqrt(b*b - 4*a*c);
A=(int)Math.floor(T);
d=(-b+A)/(2*a);
e=(-b-A)/(2*a);
if ( b*b - 4*a*c >0){
System.out.println("Two different roots x1="+d+" , x2="+e);
}
else if (b*b-4*a*c==0){
System.out.println("Two same roots x="+d);
}
else
System.out.println( "No real root");
}
}
}