Advertisement
WallHero

Punto 7 Main

Nov 13th, 2020
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Punto7 {
  4.     public static Scanner scanner = new Scanner(System.in);
  5.    
  6.     public static int forceReadPositiveInteger(String msg)
  7.     {
  8.         int ret = 0;
  9.         while(true)
  10.         {
  11.             try
  12.             {
  13.                 System.out.println(msg);
  14.                 while((ret = Integer.parseInt(scanner.next())) < 1) System.out.println("El número a cargar debe ser positivo.\n"+msg);
  15.                 return ret;
  16.             }catch (Exception e) {
  17.                 System.out.println("Error en la carga.");
  18.             }
  19.         }
  20.     }
  21.    
  22.    
  23.     public static void main(String[] args) {
  24.         int n = forceReadPositiveInteger("¿Cuántos números ingresará al árbol?");
  25.         AVLTree avl = new AVLTree();
  26.         while((n--) > 0)
  27.         {
  28.             int x = forceReadPositiveInteger("Ingrese número a ingresar");
  29.             avl.root = avl.insert(avl.root, x);
  30.         }
  31.        
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement