Member Avatar for sonicx2218

Hey everyone. As always I'm sorry for my noobness when it comes to java, but I got a question I can't seem to find answered anywhere else on the web. I'm trying to make a simple program that takes whatever number the user types in, and makes a linked linked with the # of random numbers that the user typed. So if the user types 5: you could get
100
26
89
23
54

import java.util.*;
import java.io.IOException;
import java.util.Scanner;

public class LinkedListProgram
{
    public static void main(String[] args) throws IOException
    {
        int i,number;
        Scanner sc = new Scanner(System.in);
        LinkedList<String> list = new LinkedList<String>();
        ListIterator li;
        String line;
        System.out.println("Enter # of nodes");
        number = sc.nextInt();
        if (number > 0)
            {
            while (i = 0; i <= number; i++)


            }
        else
            {
                System.out.println("\nnumber is less than 0\n");
            }
    }
}

I'm not sure how you place numbers into a linkedlist though. I got the while statement down, but idk what to put in it that will make the linked list work as I specified. Any help or tips are greatly appreciated.

Have you read the API doc for the LinkedList class to see what methods it has?

what do you want the program to do inside the while loop?

Member Avatar for sonicx2218

O wow, totally neglected that. Do you just add content to a linked list using add?

What did the API doc say? What happened when you coded it? Try it and see.

Member Avatar for sonicx2218

I literally just needed the list.add command. Way easier a fix than I thought.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.