Guest User

Untitled

a guest
Oct 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. package lista.enlazada1;
  2. import java.util.Scanner;
  3.  
  4. public class ListaEnlazada1 {
  5.  
  6. public String marca;
  7. public String modelo;
  8. public int kilometraje;
  9. public ListaEnlazada1 nodosiguiente;
  10.  
  11.  
  12. public static void main(String[] args) {
  13. /* enter the number of nodes to be created */
  14. Scanner leer= new Scanner(System.in);
  15. System.out.println("Digite la cantidad de nodos a ingresar)");
  16. int n,contador=0;
  17. n=leer.nextInt();
  18.  
  19. /* the three data of the node is entered */
  20. for (int i =1; i <= n; i++){
  21. ListaEnlazada1 nodo = new ListaEnlazada1();
  22. System.out.print("ingrese la marca ");
  23. nodo.marca=leer.next();
  24. System.out.print("ingrese el modelo ");
  25. nodo.modelo=leer.next();
  26. System.out.print("ingrese el kilometraje ");
  27. nodo.kilometraje=leer.nextInt();
  28.  
  29. /* the node is created */
  30.  
  31. if(contador==0){
  32. nodo.nodosiguiente = null;
  33. contador ++;
  34. } else {
  35. nodo.nodosiguiente = nodo;
  36. contador ++;
  37. }
  38.  
  39. /* nodes are printed */
  40. for ( i =1; i <= n; i++){
  41. System.out.println("marca " +nodo.marca+ "n");
  42. System.out.println("modelo " +nodo.modelo+ "n");
  43. System.out.println("kilometraje " +nodo.kilometraje+ "n");
  44. System.out.println("apuntador " +nodo.nodosiguiente + "n");
  45.  
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment