Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. class Elemento
  4. {
  5.   private int valor;
  6.   private Elemento proximo;
  7.   public Elemento(int v)
  8.   {
  9.     this.valor = v;
  10.     this.proximo = null;
  11.   }
  12.   public void setProximo(Elemento e)
  13.   {
  14.     this.proximo = e;
  15.   }
  16.   public Elemento getProximo()
  17.   {
  18.     return this.proximo;
  19.   }
  20.   public void imprime()
  21.   {
  22.     System.out.println("valor = " + this.valor);
  23.  
  24.   }
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. class Main {
  32.   public static int gerarNumero()
  33.   {
  34.     Random rand = new Random();
  35.     int limite = 100;
  36.     int int_random = rand.nextInt(limite);
  37.     return int_random;
  38.   }
  39.   public static void main(String[] args) {
  40.     Elemento qualquer = new Elemento(-1);
  41.     Elemento aux = qualquer;
  42.     for(int i = 0; i < 100;i++)
  43.     {
  44.       int aleatorio = gerarNumero();
  45.  
  46.       aux.setProximo(new Elemento(aleatorio));
  47.       aux = aux.getProximo();
  48.     }
  49.  
  50.     while(qualquer != null)
  51.     {
  52.       qualquer.imprime();
  53.       qualquer = qualquer.getProximo();
  54.     }
  55.  
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement