Menghitung Persamaan Kuadrat di Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package tipedatavariabel;

/**
*
* @author Angga
*/
public class persKuadrat {
double a, b, c, D, akarD;
double x1,x2;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

new persKuadrat();
}

public persKuadrat() {
System.out.println(“\nMenghitung Akar persamaan Kuadrat”);
System.out.println(“———————————“);
System.out.println(“Hitunglah akar-akar dari persamaan kuadrat x^2 – 7x + 12 = 0!\n”);
System.out.println(“Jawab:”);

a=1;
System.out.println(“a = “+a);

b=-7;
System.out.println(“b = “+b);

c=12;
System.out.println(“c = “+c);

D = b*b – 4*a*c;
System.out.println(“D = b^2 + 4ac = “+D);

akarD = Math.sqrt (D);
System.out.println(“Akar D = akar “+D+” = “+akarD);

x1 = (-b+akarD)/2*a;
x2 = (-b-akarD)/2*a;

System.out.println(“Jadi : “);
System.out.println(“x1 = (-b + akarD)/2a = “+x1);
System.out.println(“x2 = (-b – akarD)/2a = “+x2);
System.out.println(“”);

}

}

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 )

Foto Google

You are commenting using your Google 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 )

Connecting to %s