Wednesday, 18 September 2013

Difficulties using arrays, beginner

Difficulties using arrays, beginner

I am just learning using arrays in java. I am trying to assign an array
with 10 random integers, though my code is returning arrays filled with
0's. What am I doing wrong? Help would be appreciated.
import java.util.Random;
public class E7point1
{
public static void main(String[] args)
{
int[] array = new int[10];
int i = 0;
Random random = new Random();
while (i < array.length)
{
array[i] = 1 + random.nextInt(100);
i++;
}
System.out.print(array[i]);
}
}

No comments:

Post a Comment