- 1
Can anyone write this code pls? In java language
1- make empty list 2- Make the loop with 20 turns 3- Every turn, make a random number and save it in the list that you did (it is not you who wrote it, it must be a random number, the code is what you did) 4- Make a for loop, damage the numbers in the list that you did, and print the numbers in them My attempt Import java. Util. Random; Public class Rondom num { List <integer > emplist = collections.emptylist(); Public static void main(strings []args){ Rondom random = new random(); For(int i =0; i<20;i++){ Int emplist= random.nextInt(); System.out.println(emplist);
3 Respostas
+ 3
another view on your code
write
language keywords lower-case
import public for int
package names lower-case
java.util.
class names upper-case
Integer Collections String Random
//Rondom typo
Random
class name can't contain space
//public class Rondom num {
public class RandomNum {
// add right parenthesis to loop
for (...) {
...
}
Collections.emptyList() is imutable, use ArrayList instead
//List<Integer> emplist = Collections.emptyList();
List<Integer> emplist = new ArrayList<>(20);
//import other api classes
import java.util.List;
import java.util.ArrayList;
//import java.util.Collections;
emplist is non-static field,
you need create object of your class, and use it as
RandomNum rn = new RandomNum();
rn.emplist.add( number)
System.out.println( rn.emplist);
+ 2
I hope this code helps you
List<Integer> list=new ArrayList<Integer>();
int rand_int;
Random rand = new Random();
for(int i=0; i<20; i++) {
rand_int = rand.nextInt(100); // Generate random integers in range 0 to 99
list.add(rand_int);
}
System.out.println(list);
https://code.sololearn.com/crDP0Geg3c86
+ 2
Please specify a language name in post's tags
https://code.sololearn.com/W3uiji9X28C1/?ref=app