Answers for "how to find the distance between two points java"

2

java program to calculate distance between two points

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // distance between two points

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter coordinates of first point (x1,y1): ");
        int x1 = scanner.nextInt(), y1 = scanner.nextInt();

        System.out.print("Enter coordinates of second point (x2,y2): ");
        int x2 = scanner.nextInt(), y2 = scanner.nextInt();

        double distance = Math.sqrt( Math.pow(x2 - x1 ,2) + Math.pow(y2 - y1, 2) );

        System.out.println("Distance between the points is " + distance);
    }
}
Posted by: Guest on June-23-2021

Code answers related to "how to find the distance between two points java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language