ich möchte 50 random zahlen in die arraylist schreiben. bei system.out.println mit dem iterator wird aber immer nur 50 mal dieselbe zahl ausgegeben. suche jetzt ne halbe stunde und finde den fehler nicht...
Code:
/*
* Created on 18.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package firstList;
import java.util.ArrayList;
import java.util.Random;
import java.util.Iterator;
/**
* @author CHUCKY
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ThousandRandoms
{
private int randomNumber;
ArrayList al = new ArrayList(50);
public ThousandRandoms()
{
for (int i=0 ; i < 100 ; i++)
{
randomNumber = new Random().nextInt(100);
al.add(new Integer( randomNumber ));
}
}
public void showThousandRandoms()
{
Iterator it = al.iterator();
while ( it.hasNext() )
{
System.out.println( it.next() );
}
}
}
Code:
/*
* Created on 18.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package firstList;
/**
* @author CHUCKY
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ThousandRandomsTester
{
public static void main(String args[])
{
ThousandRandoms tr = new ThousandRandoms();
tr.showThousandRandoms();
}
}