I need help with generating random numbers between 0 and y and x being the amount generated in java, as you can see I am almost there, but sorting them at the end, is giving me trouble please help me get this corrected!
import java.util.Arrays;
import java.util.Scanner;
import java.util.Random;
public class RandomInt {
public static void main(String[] args) {
int[] increasingRandoms(int x, int y);
{
//establishing an array
Scanner randomScanner = new Scanner(System.in);
System.out.println("Between 0 and what integer would you like to generate random Integers? ");
y = randomScanner.nextInt();
System.out.println("Please Specify the number of Random integers you would like:");
x= randomScanner.nextInt();
//Setting x to pseudoRandom into an array in order to sort later
int[] pseudoRandom = new int [x];
for(int i =0; i< x; i++){
Random pseudo = new Random();
pseudoRandom[i] = pseudo.nextInt(y);
}
//returning an array in ascending order
Arrays.sort(pseudoRandom);
return pseudoRandom;
}
for(int number : increasingRandoms(y, x)) {
System.out.print(number + " ");
}
}
}
Aucun commentaire:
Enregistrer un commentaire