Home > OS >  How would i make this method print multiple random integers, based on the number entered in the para
How would i make this method print multiple random integers, based on the number entered in the para

Time:11-25

At the moment my method only prints a random number.

Heres the method.

    public void   printMultiRandom(int howMany){
        Random rand = new Random();
        System.out.println(rand.nextInt(howMany));

CodePudding user response:


public void printMultiRandom(int howMany){
    new Random().ints(howMany)
       .forEach(System.out::println);

}

CodePudding user response:

If you do not have any bounds on what the random number should be, you should use this..

public void printMultiRandom(int num){
    while(num-- > 0){
        double gen= 100 * Math.random();
        System.out.println(gen);
    }
}
  • Related