Jarak Dari Dua Poin

Assalamualaikum, . .
Kali ini saya akan membagikan tentang mencari jarak dari dua poin pada pemrograman java, . .
Silahkan dicoba, . .

import java.util.Scanner;

public class DistanceOfTwoPoints {

public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);

System.out.print("Enter x1 and y1: ");
double x1 = s.nextDouble();
double y1 = s.nextDouble();

System.out.print("Enter x2 and y2: ");
double x2 = s.nextDouble();
double y2 = s.nextDouble();

double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

System.out.println("The distance is " + distance);
}

}

Semoga bermanfaat, . .

Subscribe to receive free email updates:

0 Response to "Jarak Dari Dua Poin"

Post a Comment