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;
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);
}
}
}