Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MyClass {
  4.     public static void main(String args[]) {
  5.      
  6.       int x1, y1, z1;
  7.       int x2, y2, z2;
  8.       int p1, p2;
  9.      
  10.       // obtenemos la instancia de scanner, en try-resource para que se cierre cuando termine el proceso.
  11.       try (Scanner scan = new Scanner(System.in)) {
  12.          
  13.           // obtenemos los datos de la primera caja.
  14.           x1 = getInt(scan);
  15.           y1 = getInt(scan);
  16.           z1 = getInt(scan);
  17.          
  18.           // obtenemos los datos de la segunda caja
  19.           x2 = getInt(scan);
  20.           y2 = getInt(scan);
  21.           z2 = getInt(scan);
  22.       }
  23.  
  24.       // calculamos los perimetros
  25.       p1 = (x1 * 4) + (y1 * 4) + (z1 * 4);
  26.       p2 = (x2 * 4) + (y2 * 4) + (z2 * 4);
  27.  
  28.       // evaluamos los resultados
  29.       if (x1 == x2 && y1 == y2 && z1 == z2) {
  30.           System.out.println("Box 1 = Box 2");
  31.       } else if (p1 < p2) {
  32.           System.out.println("Box 1 < Box 2");
  33.       } else if (p1 > p2) {
  34.           System.out.println("Box 1 > Box 2");
  35.       } else {
  36.           System.out.println("Imcomparable");
  37.       }
  38.      
  39.     }
  40.  
  41.     /**
  42.      * Devuelve el entero ingresado en la consola o emite un runtime exception si no existe el valor.
  43.      *
  44.      **/
  45.     public static int getInt(Scanner scan) {
  46.         if (scan.hasNextInt()) {
  47.             return scan.nextInt();
  48.         }
  49.        
  50.         throw new RuntimeException("Parametro faltante");
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement