-
Lenguaje
Java usando Scanner
-
Descripción
Dadas las coordenadas de dos puntos en un plano cartesiano calcule la distancia entre ellos.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;
public class DistanciaEntreDosPuntos {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double distancia, x1, x2, y1, y2;
System.out.print("Ingresa el valor de x1: ");
x1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de x2: ");
x2 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de y1: ");
y1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de y2: ");
y2 = in.nextDouble();
in.nextLine();
distancia=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
System.out.println("Valor de distancia: " + distancia);
}
}
public class DistanciaEntreDosPuntos {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double distancia, x1, x2, y1, y2;
System.out.print("Ingresa el valor de x1: ");
x1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de x2: ");
x2 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de y1: ");
y1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de y2: ");
y2 = in.nextDouble();
in.nextLine();
distancia=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
System.out.println("Valor de distancia: " + distancia);
}
}