Advertisement
eightmoons

LInkedLIstApp v1.1.java

Oct 26th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.LinkedList;
  2. import java.util.Random;
  3.  
  4. public class LinkedListApp {
  5.  
  6.     public static void main(String[] args) {
  7.         int maxNumbers = 10;
  8.         LinkedList<Integer> firstList = new LinkedList<>();
  9.         //linked list of postive integer randon numbers
  10.         Random randomizer = new Random();
  11.         for (int iCount = 0; iCount< maxNumbers; iCount++){
  12.             firstList.add(randomizer.nextInt(100));
  13.         }
  14.         //second linked list with the first's integers and removal first linked list's items
  15.         LinkedList<Integer> secondList = new LinkedList<>();
  16.         for (Integer num :
  17.                 firstList) {
  18.             secondList.add(num);
  19.             firstList.remove(num);
  20.         }
  21.  
  22.         //display second linked list items
  23.         String comma = "";
  24.         for (Integer num :
  25.                 secondList) {
  26.             System.out.print(comma + num);
  27.             comma = ", ";
  28.         }
  29.  
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement