Random Star
Write a method named randomStar that takes two parameters, a Random object r and an integer num. The method should keep printing lines of * characters, where each line has between 5 and 19 * characters inclusive, until it prints a line with greater than or equal to num characters. num is guaranteed to be between 5 and 19. For example, the method call randomStar(14) will print:
import java.util.*;
public class RandomStar {
public static void main(String[] args) {
Random r = new Random(2063064142); // ignore the 2063064142
randomStar(r, 12);
System.out.println();
randomStar(r, 19);
}
public static void randomStar(Random r, int num) {
}
}

Respuesta :

Answer:

Explanation:

The following code is written in Java. The function takes in the random object and creates a random number where it generates a random number and prints out the * characters, if the random number and the input num are the same it prints out both values and ends the function.

import java.util.Random;

class Brainly {

   public static void main(String[] args) {

       Random r = new Random();

       randomStar(r, 12);

       System.out.println();

       randomStar(r, 19);

   }

   public static void randomStar(Random r, int num) {

       while (true) {

           int randomNum = r.nextInt(19) + 5;

           if (randomNum != num) {

               for (int x = 0; x < randomNum; x++) {

                   System.out.print("*");

               }

               System.out.print("\n");

           } else {

               for (int x = 0; x < randomNum; x++) {

                   System.out.print("*");

               }

               System.out.print("\n");

               System.out.println("Random Number: " + randomNum);

               System.out.println("Input Number: " + num);

               break;

           }

       }

   }

}

Ver imagen sandlee09