diff --git a/src/P112_RadaresDeTramo.java b/src/P112_RadaresDeTramo.java index 938562f..8ff6b86 100644 --- a/src/P112_RadaresDeTramo.java +++ b/src/P112_RadaresDeTramo.java @@ -1,7 +1,7 @@ import java.util.Scanner; public class P112_RadaresDeTramo { - public static void main() { + public static void main(String[] args) { Scanner sc = new Scanner(System.in); int distancia = 0; // Distancia entre las cámaras (metros) int velPermitida = 0; // Velocidad máxima permitida (Km/h) diff --git a/src/P164_AreaRectangulo.java b/src/P164_AreaRectangulo.java index 93128a5..fef23d7 100644 --- a/src/P164_AreaRectangulo.java +++ b/src/P164_AreaRectangulo.java @@ -1,23 +1,27 @@ import java.util.Scanner; -void main() { - Scanner sc = new Scanner(System.in); - // Coordenadas de las esquinas opuestas - int ax, ay, bx, by; - // Longitud de lados - int l1, l2; - // Area del rectangulo - int area; - while(true) { - System.out.print("Introduce las coordenadas del rectángulo (ax ay bx by): "); - ax = sc.nextInt(); - ay = sc.nextInt(); - bx = sc.nextInt(); - by = sc.nextInt(); - // Ternario para obtener resta positiva - l1 = (ax < bx) ? bx - ax : ax - bx; - l2 = (ay < by) ? by - ay : ay - by; - area = l1 * l2; - System.out.println("El área es: " + area); +public class P164_AreaRectangulo { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + // Coordenadas de las esquinas opuestas + int ax, ay, bx, by; + // Longitud de lados + int l1 = 0, l2 = 0; + // Area del rectangulo + int area; + while (true) { + ax = sc.nextInt(); + ay = sc.nextInt(); + bx = sc.nextInt(); + by = sc.nextInt(); + + // Omitir casos de prueba + if(ax > bx || ay > by) break; + + l1 = bx - ax; + l2 = by - ay; + area = l1 * l2; + System.out.println(area); + } } } \ No newline at end of file diff --git a/src/P481_Ajedrez.java b/src/P481_Ajedrez.java index 999333a..913e84b 100644 --- a/src/P481_Ajedrez.java +++ b/src/P481_Ajedrez.java @@ -1,18 +1,18 @@ // Convertir la posición del tablero de ajedrez en números // a notación algebraica. Ex: 5 2 -> d 2 -void main() { - Scanner sc = new Scanner(System.in); - int h = 0, v = 0; - do { - System.out.println("Introduce la casilla del tablero con numeros: "); - h = sc.nextInt(); - v = sc.nextInt(); - if (h == 0 && v == 0) break; - if (h < 1 || v < 1 || h > 8 || h > 8) { - System.out.println("ERROR: Casillas inválidas"); - return; - } - char letra = (char) ((8 - h) + (int) ('a')); - System.out.printf("%c %d\n", letra, v); - } while (true); + +import java.util.Scanner; + +public class P481_Ajedrez { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int h = 0, v = 0; + do { + h = sc.nextInt(); + v = sc.nextInt(); + if (h == 0 && v == 0) break; + char letra = (char) ((8 - h) + (int) ('a')); + System.out.printf("%c%d\n", letra, v); + } while (true); + } } \ No newline at end of file