corregir ajedrez aceptarelreto

This commit is contained in:
PC de clase committed 2026-10-15 13:38:14 +02:00
1 parent 4070327d70
commit 26368fc149
2 files changed
+38 -34

No files matched your search

+23 -19
View File
@@ -1,23 +1,27 @@
import java.util.Scanner; import java.util.Scanner;
void main() { public class P164_AreaRectangulo {
Scanner sc = new Scanner(System.in); public static void main(String[] args) {
// Coordenadas de las esquinas opuestas Scanner sc = new Scanner(System.in);
int ax, ay, bx, by; // Coordenadas de las esquinas opuestas
// Longitud de lados int ax, ay, bx, by;
int l1, l2; // Longitud de lados
// Area del rectangulo int l1 = 0, l2 = 0;
int area; // Area del rectangulo
while(true) { int area;
System.out.print("Introduce las coordenadas del rectángulo (ax ay bx by): "); while (true) {
ax = sc.nextInt(); ax = sc.nextInt();
ay = sc.nextInt(); ay = sc.nextInt();
bx = sc.nextInt(); bx = sc.nextInt();
by = sc.nextInt(); by = sc.nextInt();
// Ternario para obtener resta positiva
l1 = (ax < bx) ? bx - ax : ax - bx; // Omitir casos de prueba
l2 = (ay < by) ? by - ay : ay - by; if(ax > bx || ay > by) break;
area = l1 * l2;
System.out.println("El área es: " + area); l1 = bx - ax;
l2 = by - ay;
area = l1 * l2;
System.out.println(area);
}
} }
} }
+15 -15
View File
@@ -1,18 +1,18 @@
// Convertir la posición del tablero de ajedrez en números // Convertir la posición del tablero de ajedrez en números
// a notación algebraica. Ex: 5 2 -> d 2 // a notación algebraica. Ex: 5 2 -> d 2
void main() {
Scanner sc = new Scanner(System.in); import java.util.Scanner;
int h = 0, v = 0;
do { public class P481_Ajedrez {
System.out.println("Introduce la casilla del tablero con numeros: "); public static void main(String[] args) {
h = sc.nextInt(); Scanner sc = new Scanner(System.in);
v = sc.nextInt(); int h = 0, v = 0;
if (h == 0 && v == 0) break; do {
if (h < 1 || v < 1 || h > 8 || h > 8) { h = sc.nextInt();
System.out.println("ERROR: Casillas inválidas"); v = sc.nextInt();
return; if (h == 0 && v == 0) break;
} char letra = (char) ((8 - h) + (int) ('a'));
char letra = (char) ((8 - h) + (int) ('a')); System.out.printf("%c%d\n", letra, v);
System.out.printf("%c %d\n", letra, v); } while (true);
} while (true); }
} }