public class ContohIfElse {
public static void main(String[] args){
double a = 4 ;
double b = -13 ;
double c = -12 ;
double d = b*b - 4*a*c ;
double x1, x2;
System.out.println("persamaan kuadrat a*x^2+b*x+c=0, dimana");
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
System.out.println("dengan menerapkan rumus ABC diketahui bahwa : ");
if (d<0){
System.out.println("akar akar persamaan nyata tetapi kembar");
x1 = -b/(2*a);
System.out.println("x1 = x2 ="+x1);
}else{
System.out.println("akar akar persamaan nyata dan berbeda");
x1 = (-b+Math.sqrt(d))/(2*a);
x2 = (-b-Math.sqrt(d))/(2*a);
System.out.println("x1 = " +x1+ "x2 = "+x2);
}
}
}
public static void main(String[] args){
double a = 4 ;
double b = -13 ;
double c = -12 ;
double d = b*b - 4*a*c ;
double x1, x2;
System.out.println("persamaan kuadrat a*x^2+b*x+c=0, dimana");
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
System.out.println("dengan menerapkan rumus ABC diketahui bahwa : ");
if (d<0){
System.out.println("akar akar persamaan nyata tetapi kembar");
x1 = -b/(2*a);
System.out.println("x1 = x2 ="+x1);
}else{
System.out.println("akar akar persamaan nyata dan berbeda");
x1 = (-b+Math.sqrt(d))/(2*a);
x2 = (-b-Math.sqrt(d))/(2*a);
System.out.println("x1 = " +x1+ "x2 = "+x2);
}
}
}
0 comments