+ 1
Can someone explain why this is not working?
import java.util.*; public class RandomList{ public static void main(String[] args){ Random rnd=new Random(); int[]arr= new int[5]; for(int i=0;i<5;i++) arr[i] = rnd.nextInt(10)+1; List<int> It= new ArrayList<int>(); for(int z:arr); It.add(z); } }
7 Answers
+ 10
; after for each == empty statement > add is only executed once.
+ 5
replace <int> with <Integer>
Sorry man
+ 2
@Enes Nope
0
When I run that im getting an error message saying "RandomList.java:9"
RandomList.java:9error: type List does not take parameters
And ; expected at for(int i=0, i<5;i++;)
^
0
@Anthony replace , with ; in for loop
for(int i=0; i<5;i++)
0
@meharban: thats what i was thinking. Im still getting the parameters error message. Thanks for trying to help though.
0
Instead of 'List' in your
---> List<int> It= new ArrayList<int>();
shouldn't it be ArrayList<Integer> It= new ArrayList<Integer>(0);
?