hello everyone. I can't figure out how to create a random int that gets placed into a linked list.
import java.util.*;
import java.io.IOException;
import java.util.Scanner;
import java.util.Random;
public class LinkedListProgram
{
public static void main(String[] args) throws IOException
{
int i,number, ran;
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)
{
for (i = 0; i <= number; i++)
list.add("random number");
System.out.print(list + "\n");
}
else
System.out.println("\nnumber is less than 0\n");
}
}
Where it says list.add("random number") I want it to have an actual equation that will create a random # so it's differrent everytime. Nothing I've tried works. Any help on this is greatly appreciated.