Skip to content

Instantly share code, notes, and snippets.

@itsKnight847
Last active October 27, 2017 09:03
Show Gist options
  • Save itsKnight847/6d3aa7f17d29eb29d730284f3f377cad to your computer and use it in GitHub Desktop.
Save itsKnight847/6d3aa7f17d29eb29d730284f3f377cad to your computer and use it in GitHub Desktop.
/**
* Author: Leon Beilis
* Desription: A Program that asks for two dotes
* and calculate their distance on the Coordinate system
* by known math formula
*/
import java.util.Scanner;
public class Line {
public static void main() {
//initilize scanner
Scanner scan = new Scanner(System.in);
System.out.println("The Program will ask for 2 points (x,y) and will calculate the distance between them");
// get first point from user
System.out.println("Please enter x1 value:");
int x1 = scan.nextInt();
System.out.println("Please enter y1 value:");
int y1 = scan.nextInt();
// get second point from user
System.out.println("Please enter x2 value:");
int x2 = scan.nextInt();
System.out.println("Please enter y2 value:");
int y2 = scan.nextInt();
/**
* declare distance variable
* calc the distance between the points and insert to the distance variable
*/
double distanceBetweenTwoPoints;
distanceBetweenTwoPoints = Math.sqrt( Math.pow( x1 - x2 ,2) + Math.pow( y1 - y2 ,2) );
//print the points and their distance between eachother
System.out.println("the distance between point ("+x1+","+y1+") and point ("+x2+","+y2+") is: " + distanceBetweenTwoPoints );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment