He wants to input in the program an undefinite number of (numbers like 1, 2 etc), all positive. With that done he wants the program to randomize these numbers and show them one at a time in a random distribution. i thought it was easier when he asked but i found out while writing it that its not that easy. i need help. anyone?

## Grn Xtrm 84

First you can have the user input the number of values to input into the data structure(arrays are a good choice). Then use a for loop to ask the user to put in each value.

thx for ut reply.. heres what ive done. could u kindly check it for me?

``````//allow for input
import javax.swing.*;
import java.util.*;

public class Sorteggio
{
public static void main (String[] args)
{

int numero;
ArrayList numero = new ArrayList();

//loop part
boolean cont = false;
do
{
cont = false;

//allows for input
int choice = Integer.parseInt(JOptionPane.showInputDialog("Type\n"+"1 to add new number\2"+"2 to show random number"));

if(choice==1)
{
//metti il numero
int scelta = Integer.parseIntJOptionPane.showInputDialog("what number would you like to add");
}
if(choice==2)
{
String output = "your number is..\n";
output+=((int)randomnumber);
//we randomize the numbers
int randomnumber = Math.random(numero);
JOptionPane.showMessageDialog(null, output);
}
//input to repeat
String repeat = JOptionPane.showInputDialog("Again?");
if(repeat.equals("si"))
cont = true;
}
while(cont);
}
}
``````

## JamesCherrill 3,661

As the user enters numbers add them to a List ( http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html ). Then in a loop generate a random integer between 0 and the size() of the list. Get(int index) the element at that index, print it, then remove(int index) that element. Loop until the List is empty.

## Grn Xtrm 84

I would get rid of this

``int numero;``

I do input using the predefined scanner class

``````Scanner scan = new Scanner(System.in);
System.out.println("Enter how many numbers will be added");
int nums = scan.nextInt();
System.out.println("Input the numbers");
for(int index = 0; index<nums; ++index)
{
int input = scan.nextInt();
}``````

That's how I add user input numbers into the list.
By the way. Are you Italian?

yeah i am from rome.

sry but i am very new to java and this is the first prog i get to do.. should i add that part like this?

``````import java.util.*;

public class Sorteggio
{
public static void main (String[] args)
{

ArrayList numero = new ArrayList();

//loop part
boolean cont = false;
do
{
cont = false;

//allows for input
Scanner scan = new Scanner(System.in);
System.out.println("Enter how many numbers will be added");
int nums = scan.nextInt();
System.out.println("Input the numbers");
for(int index = 0; index<nums; ++index)
{
int input = scan.nextInt();
}
``````

how should i continue i think i was doing it wrong before

## Grn Xtrm 84

The code segment I provided earlier is just to get the numbers into the list. Sorry, but I don't know that much about random numbers. Try searching on google.com.

## JamesCherrill 3,661

Now you have your numbers, follow the instructions in post #4 above to randomise and output them.

thank you guys for the help however its a bit too complicated for me at this level. this is not a course im taking but personal interest in programming and i thought java is good intro to programming in general. ive been learning using pdf books for the past week and i let a few friends now about it. this particular friends needs this prog in less than two weeks but i might not be able to learn what i need to learn and then write it by then. it would help a lot if u could tell me the steps and procedure to make this work. also im a bit lost between the posts and im still unsure if my previous attempt worked or i should completely rewrite it. thx for ur time!

## BestJewSinceJC 700

If you were to make this Friend into a Java class, would it implement Professor?

If you were to make this Friend into a Java class, would it implement Professor?

the simple fact you cannot conceive an individual learning to program as personal interest somehow gives me some credit. im learning as a passion towards the world of coding and computers, and linux too. but you.. such mistrust in people is a reflection of you who are and the programs you probably write: unhelpful, full of bugs and lack of faith.
thx u for ur post anyway, very insightful.

## BestJewSinceJC 700

It was a joke, relax. But if you really want to learn, you'll take the suggestions you've already been given, learn how to code those individual pieces, then put them together.