I am new in java and I have a question about how to create a random array method with a number in the range 1-50
I need to give him the size of the array and he should create an array by the size I gave it to him and the elements of this array from 1-50
I try this code but it's never working with me
public class NewClass {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the number ");
int r = input.nextInt();
int[] list = new int[r];
for (int i=0; i<10; i++){
int n = (int)(Math.random()*50 + 1);
list[i] = n;
System.out.println(list[i] + " ");
}
}
Aucun commentaire:
Enregistrer un commentaire