-
Lenguaje
Java usando Scanner
-
Descripción
Dos vehículos viajan a diferentes velocidades (v1 y v2) y están distanciados por una distancia d. El que está detrás viaja a una velocidad mayor. Se pide ingresar la distancia entre los dos vehículos (km) y sus respectivas velocidades (km/h) y con esto determinar y mostrar en que tiempo (minutos) alcanzará el vehículo más rápido al otro.
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 TiempoEnAlcanzarUnVehiculo {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double d, tiempo, v1, v2;
System.out.print("Ingresa el valor de d: ");
d = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de v1: ");
v1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de v2: ");
v2 = in.nextDouble();
in.nextLine();
if(v1>v2)
tiempo=d*60/(v1-v2);
else
tiempo=d*60/(v2-v1);
System.out.println("Valor de tiempo: " + tiempo);
}
}
public class TiempoEnAlcanzarUnVehiculo {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double d, tiempo, v1, v2;
System.out.print("Ingresa el valor de d: ");
d = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de v1: ");
v1 = in.nextDouble();
in.nextLine();
System.out.print("Ingresa el valor de v2: ");
v2 = in.nextDouble();
in.nextLine();
if(v1>v2)
tiempo=d*60/(v1-v2);
else
tiempo=d*60/(v2-v1);
System.out.println("Valor de tiempo: " + tiempo);
}
}