Created
September 21, 2022 17:43
-
-
Save spukles/8fd741de30374559b9fe7ffd4cfb8400 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class DistanceCalculation{ | |
public static void main(String[] args){ | |
//create scanner | |
Scanner scanner = new Scanner(System.in); | |
//input coordinates, use double&nextdouble | |
System.out.print("Enter value of x Coordinate for Point 1:"); | |
double x1 = scanner.nextDouble(); | |
System.out.print("Enter value of y Coordinate for Point 1:"); | |
double y1 = scanner.nextDouble(); | |
System.out.print("Enter value of x Coordinate for Point 2:"); | |
double x2 = scanner.nextDouble(); | |
System.out.print("Enter value of y Coordinate for Point 2:"); | |
double y2 = scanner.nextDouble(); | |
//compute the math.sqrt to give the distance between two points calculation | |
double distance = Math.sqrt((x2-x1) * (x2-x1) + (y2-y1)*(y2-y1)); | |
//print the distance between 2 points | |
System.out.println("The distance between two points:" + distance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment