Skip to content

Instantly share code, notes, and snippets.

@joeyv
Last active December 26, 2015 05:59
Show Gist options
  • Select an option

  • Save joeyv/7104734 to your computer and use it in GitHub Desktop.

Select an option

Save joeyv/7104734 to your computer and use it in GitHub Desktop.
Simple program to calculate the distance of two coordinates
import java.util.*;
public class Distance
{
public static void main(String[] args)
{
int x1, y1;
int x2, y2;
int inside, distance;
Scanner scan = new Scanner(System.in);
x1 = scan.nextInt();
y1 = scan.nextInt();
x2 = scan.nextInt();
y2 = scan.nextInt();
//equation inside of the square root
inside = (int)Math.pow((x2-x1), 2) + (int)Math.pow((y2-y1), 2);
//sqaure root of the inside
distance = (int)Math.sqrt(inside);
System.out.println (distance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment