Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago