Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Im trying to print a random integer, a N amount fo times and im trying to use a for loop to work it.

What I have tried:

Heres my method that is currently giving me the error int cannot be converted in boolean.
Java
public void printMutliRandom(int howMany){
        Random rand = new Random();
        for(howMany=0; howMany++;){
            System.out.println(rand.nextInt());
        }
    }
Posted
Updated 24-Nov-22 11:17am

1 solution

I have found a solution now

/**
     * Print multiple random intergers values using System.out.println.
     * @param howMany How many random values to print.
     */
    public void printMutliRandom(int howMany){
        Random rand = new Random();
        for(int i = 0; i < howMany; i++){
            System.out.println(rand.nextInt());
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900