0

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.

2
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by sonicx2218
0

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?

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.