Bad exit to screen of this program

1

I have this code.

  public static void añadir(CListaTfonos listatfnos){
        try {               
            String nombre;
            String direccion;
            long telefono;

             System.out.println("telefono: ");
            telefono=leer.nextLong();

            System.out.println("direccion: ");
            direccion=leer.nextLine();

            System.out.println("nombre: ");
            nombre=leer.nextLine();

            listatfnos.añadir(new CPersona(nombre, direccion, telefono));                
        } catch (Exception e) {}
    }

When showing on the screen I should show something like this

teléfono: 12345
dirección: ejemplo
nombre: jose

The problem is that on the screen running the program and selecting the option -add- from a switch shows it to me like this

 teléfono: 12345

 dirección: nombre: jose

He does not let me add the address, he jumps it, he jumps it, he omits it. Why is that happening? How can I solve it? If I move it, make it look like this

    System.out.println("telefono: ");
    telefono=leer.nextLong();
    System.out.println("nombre: ");
    nombre=leer.nextLine();
    System.out.println("direccion: ");
    direccion=leer.nextLine();

shows it like this

 teléfono:12345

 nombre: dirección: ejemplo
    
asked by Jose Luis 26.11.2016 в 04:53
source

1 answer

2

The drawback is that the method nextLong ()

answered by 26.11.2016 / 05:02
source