Created
October 18, 2013 16:41
-
-
Save imryan/7044256 to your computer and use it in GitHub Desktop.
Distance formula calculator.
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.*; | |
| public class Distance { | |
| public static void main(String[] args) { | |
| // Declare variables | |
| Scanner sc = new Scanner(System.in); | |
| int x1, x2, y1, y2; | |
| // Get input(s) | |
| x1 = sc.nextInt(); | |
| y1 = sc.nextInt(); | |
| x2 = sc.nextInt(); | |
| y2 = sc.nextInt(); | |
| // Call distance calculation method | |
| double distance = getDistance(x1, y1, x2, y2); | |
| System.out.println("Distance between (" + x1 + ", " + x2 + ") and (" + y1 + ", " + y2 + ") is: " + distance); | |
| } | |
| public static double getDistance(int x1, int y1, int x2, int y2) | |
| { | |
| return Math.ceil(Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment