Menghitung Persamaan Garis Lurus di Java

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

package tipedatavariabel2;

/**
*
* @author Angga
*/
public class PersamaanGarisLurus {

double x1, y1, x2, y2;
double gradien, c;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new PersamaanGarisLurus ();
}
public PersamaanGarisLurus () {
System.out.println(“\nMencari Persamaan garis lurus melalui 2 titik”);
System.out.println(“———————————————“);
System.out.println(“Carilah Persamaan garis lurus yang melalui titik (6,5) dan (-2,1)!\n”);

System.out.println(“Jawab :”);
x1=6;
System.out.println(“x1 = “+x1);

y1=5;
System.out.println(“y1 = “+y1);

x2=-2;
System.out.println(“x2 = “+x2);

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

// y = mx + c, => m = gradien
// m = (y2 – y1)/(x2-x1)
// c = y – mx
gradien = (y2 – y1)/(x2-x1);
System.out.println(“gradien = (y2-y1)/(x2-x1) = “+gradien);
c = 5 – gradien*6; // ambil salah satu titik misal titik (6,5)
System.out.println(“c = y – mx = “+c);
System.out.println(“Jadi persamaan garis lurus yang melalui titik (6,5) dan (-2,1) adalah: “);
System.out.println(“y = mx + c => y = “+gradien+”X”+” + “+c);
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