Write a method named randomX that keeps printing lines, where each line contains
ID: 3654226 • Letter: W
Question
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, and can not get it to work import java.util.*; public class RandomX{ public static void main(String[] args){ randomX(); } publicstaticvoidrandomX(){ Randomrand=newRandom(); intlinesCount=rand.nextInt(9)+2; for(inti=1;i<=linesCount;i++){ intxCount=rand.nextInt(15)+5; for(intj=1;j<=xCount;j++){ System.out.print("x"); } System.out.println(); } } }Explanation / Answer
package Cramster; import java.util.Random; public class RandomX { public static void main(String[] args) { randomX(); } public static void randomX() { Random rand = new Random(); while(true) { int xCount = rand.nextInt(15)+5; for(int j=0;j = 16) break; } } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.