Write the method stopAtFive (int j)
instructions are below:
write the code for the method, where you keep generating random numbers from 1 to 10 until you get j number of 5’s. Every time you get a 5, you go to the next line. Once you get to j number of 5’s, you stop. For example: if j was equal to 3, then a possible output printed to console is like:
183925
135
19292084185
As you can see from the above output, there was 3 lines because j equals 3, with each line ending with 5. That is what we are trying to do here.
Whenever you get to a 5, you go to the next line and repeat until there are j number of 5’s. Remember to print to console.

Respuesta :

public class JavaApplication62 {

   public static void stopAtFive(int j){

       int i = 0;

       while (i < j){

           int x = (int) (Math.random() * 10);

           if (x == 5){

               System.out.println(x);

               i++;

           }

       }

   }

   public static void main(String[] args) {

       stopAtFive(3);

   }

   

}

I hope this helps!

ACCESS MORE