Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- class Elemento
- {
- private int valor;
- private Elemento proximo;
- public Elemento(int v)
- {
- this.valor = v;
- this.proximo = null;
- }
- public void setProximo(Elemento e)
- {
- this.proximo = e;
- }
- public Elemento getProximo()
- {
- return this.proximo;
- }
- public void imprime()
- {
- System.out.println("valor = " + this.valor);
- }
- }
- class Main {
- public static int gerarNumero()
- {
- Random rand = new Random();
- int limite = 100;
- int int_random = rand.nextInt(limite);
- return int_random;
- }
- public static void main(String[] args) {
- Elemento qualquer = new Elemento(-1);
- Elemento aux = qualquer;
- for(int i = 0; i < 100;i++)
- {
- int aleatorio = gerarNumero();
- aux.setProximo(new Elemento(aleatorio));
- aux = aux.getProximo();
- }
- while(qualquer != null)
- {
- qualquer.imprime();
- qualquer = qualquer.getProximo();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement