Write a method named randomx


Write a method named randomX that keeps printing lines, where each line contains a random number of x characters between 5 and 19 inclusive, until it prints a line with 16 or more characters. For example, the output from your method might be the following. Notice that the last line has 17 x characters.

xxxxxxx
xxxxxxxxxxxxx
xxxxxx 
xxxxxxxxxxx
xxxxxxxxxxxxxxxxx
(Because this problem uses random numbers, our test cases check only the general format of your output. You must still examine the output yourself to make sure the answer is correct.)

This is what I got, but cannot get it to work
import java.util.*;
public class RandomX{
public static void main(String[] args){
randomX();
}

public static void randomX(){
Random rand = new Random();
int linesCount = rand.nextInt(9) + 2;

for (int i = 1; i <= linesCount; i++) {
int xCount = rand.nextInt(15) + 5;

for (int j = 1; j <= xCount; j++) {
System.out.print("x");
}
System.out.println();
}


}

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Write a method named randomx
Reference No:- TGS096730

Expected delivery within 24 Hours