bahasa java

program menghitung persamaan kuadrat


package javaapplication1;
import java.io.*;
public class Main {
public static void main(String[] args) {
BufferedReader akar = new BufferedReader(
new InputStreamReader(System.in));
String angka1=””;
double a=0;
double b=0;
double c=0;
double d=0;
double x1=0,x2=0;
System.out.println(“Mencari Akar-Akar Persamaan Kuadrat”);
System.out.println(”           ax^2 + bx + c”);
System.out.print(“Masukkan nilai A = “);
try {
angka1 = akar.readLine();
a = Double.parseDouble(angka1);

} catch (IOException e) {
System.out.println(“input”);
}
System.out.print(“Masukkan nilai B = “);
try {
angka1 = akar.readLine();
b = Double.parseDouble(angka1);

} catch (IOException e) {
System.out.println(“input”);
}
System.out.print(“Masukkan nilai C = “);
try {
angka1 = akar.readLine();
c = Double.parseDouble(angka1);

} catch (IOException e) {
System.out.println(“input”);
}

System.out.println(“Rumus D = B^2-4AC”);
System.out.println(“D =(“+b+”*”+b+”)”+”-(4*”+a+”*”+c+”)”);
d=(b*b)-(4*a*c);
System.out.println(“Nilai D = “+ d);
if (d<0)
{System.out.println(“Persamaan akar-akar imajiner”);}
else if (d>0)
{   x1 = (-b + Math.sqrt(d)) / 2 * a;
x2 = (-b – Math.sqrt (d)) / 2 * a;
System.out.println(“x1 = ” + x1);
System.out.println(“x2 = ” + x2);}
else if (d==0)
{   x1 = (-b + Math.sqrt(d)) / 2 * a;
x2 = x1;
System.out.println(“x1 = ” + x1);
System.out.println(“x2 = ” + x2);}
}

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: