This commit is contained in:
2024-11-05 14:54:07 +03:00
parent b1f377bfec
commit 2986cfa864
6 changed files with 62 additions and 0 deletions

27
labs/lab3/Distance.java Normal file
View File

@ -0,0 +1,27 @@
// *************************************************************
// Distance.java
//
// Computes the distance between two points
// *************************************************************
import java.util.Scanner;
public class Distance
{
public static void main (String[] args)
{
double x1, y1, x2, y2; // coordinates of two points
double distance; // distance between the points
Scanner scan = new Scanner(System.in);
// Read in the two points
System.out.print ("Enter the coordinates of the first point " +
"(put a space between them): ");
x1 = scan.nextDouble();
y1 = scan.nextDouble();
System.out.print ("Enter the coordinates of the second point: ");
x2 = scan.nextDouble();
y2 = scan.nextDouble();
// Compute the distance
// Print out the answer
distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
System.out.println("Distance between them: "+distance);
}
}