Hey bros. I made a program that prints out random numbers in a linked list. I want to have the index number next to each of the random numbers in the list. I guess for example like:
Here's m program so far, and it only sorts and prints out the list, but doesn't have an index next to each random integer. I think you use a list iterator to do this, but I can't figure it out... my output right now is like [23 58 129] but I kinda of want it to be like the list I made above.
Here's the code.
public class LinkedListProgram
public static void main(String args) throws IOException
int i,number, ran;
Scanner sc = new Scanner(System.in);
LinkedList<Integer> list = new LinkedList<Integer>();
Random random = new Random();
int pick = random.nextInt(150);
System.out.println("Enter # of nodes");
number = sc.nextInt();
if (number > 0)
for (i = 0; i < number; i++)
System.out.print(list + "\n");
System.out.println("\nnumber is less than 0\n");
Any helps is SUUUUPER APRECIATED. Thanks so much for all your times!
1 Year Ago
Related Article:java list
is a solved Java discussion thread by anisha.silva that has 1 reply, was last updated 3 months ago and has been tagged with the keywords: java, method, list.