Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MyClass {
- public static void main(String args[]) {
- int x1, y1, z1;
- int x2, y2, z2;
- int p1, p2;
- // obtenemos la instancia de scanner, en try-resource para que se cierre cuando termine el proceso.
- try (Scanner scan = new Scanner(System.in)) {
- // obtenemos los datos de la primera caja.
- x1 = getInt(scan);
- y1 = getInt(scan);
- z1 = getInt(scan);
- // obtenemos los datos de la segunda caja
- x2 = getInt(scan);
- y2 = getInt(scan);
- z2 = getInt(scan);
- }
- // calculamos los perimetros
- p1 = (x1 * 4) + (y1 * 4) + (z1 * 4);
- p2 = (x2 * 4) + (y2 * 4) + (z2 * 4);
- // evaluamos los resultados
- if (x1 == x2 && y1 == y2 && z1 == z2) {
- System.out.println("Box 1 = Box 2");
- } else if (p1 < p2) {
- System.out.println("Box 1 < Box 2");
- } else if (p1 > p2) {
- System.out.println("Box 1 > Box 2");
- } else {
- System.out.println("Imcomparable");
- }
- }
- /**
- * Devuelve el entero ingresado en la consola o emite un runtime exception si no existe el valor.
- *
- **/
- public static int getInt(Scanner scan) {
- if (scan.hasNextInt()) {
- return scan.nextInt();
- }
- throw new RuntimeException("Parametro faltante");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement