Arreglar radares de tramo

This commit is contained in:
PC de clase committed 2026-09-21 12:42:38 +02:00
1 parent 6ad15af53b
commit a01c50d36c
2 files changed
+28 -14

No files matched your search

+6 -2
View File
@@ -1,6 +1,6 @@
import java.util.Scanner;
public class RadaresDeTramo {
public class P112_RadaresDeTramo {
public static void main() {
Scanner sc = new Scanner(System.in);
int distancia = 0; // Distancia entre las cámaras (metros)
@@ -8,11 +8,15 @@ public class RadaresDeTramo {
int tiempo = 0; // Tiempo que tarda el coche en pasar entre las cámaras (segundos)
while(true) { // Condición de salida después de obtener datos
System.out.print("Introduce los datos: ");
distancia = sc.nextInt();
velPermitida = sc.nextInt();
tiempo = sc.nextInt();
sc.nextLine(); // Limpiar stdin
// Validar que los datos sean mayores que 0
if (distancia < 0 || velPermitida < 0 || tiempo < 0) {
System.out.println("ERROR");
continue;
}
// Salir del bucle
if (distancia == 0 && velPermitida == 0 && tiempo == 0) {
System.out.println("SALIR");