Question: Write a program that generates random integers between 3 and 30 (both inclusive). Build a method called printHouse that is passed an odd integer n

Write a program that generates random integers between 3 and 30 (both inclusive). Build a method called printHouse that is passed an odd integer n (the first odd randomly generated integer above that is greater than or equal to 7) and a String s (choose between *, $, and #), and that prints a house-like shape using s. The top of the house is a pyramid and the bottom of the house is a square with one less row. The top row of the pyramid prints the string a single time. The second row prints two extra strings and so on. The last row of the pyramid prints the string s, n times. You must reuse the methods youve already written in the class especially makeRow.

Sample: Calling printHouse(11, "*"); from main, prints the following:

Write a program that generates random integers between 3 and 30 (both

So basically, if n is 11, 6 rows of pyramid and 5 rows of squares are printed. You have to figure out the number of rows if n is 13 or 21 or 23 etc. Your whole solution hinges upon the loop counters. Be wise.

//makeRow

public static String makeRow(int num, String str){

String temp = "";

for(int i=0 ;i

temp = temp + str;

}

return temp;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!