Docsity

Printing Rectangles of Characters using Java, Study notes of Software Engineering

Toggle sidebar
bg1
Improvement to replicate
โ€ขAdd another function replicate that prints the character โ€˜*โ€™ a
specified number of times on one line. The method should look like
this:
public static void replicate(int times)
times is the number of times โ€˜*โ€™ is printed on one line.
โ€ข Test the method by making a call to replicate method in the main
program like this:
replicate(25)
What shows up on the screen?
pf3
pf4
pf5

Partial preview of the text

Download Printing Rectangles of Characters using Java and more Study notes Software Engineering in PDF only on Docsity!

Improvement to

replicate

-^ Add^ another function

replicate^ that prints the character

โ€˜*โ€™^ a

specified number of times

on one line. The method should look like this:^ public^ static

void^ replicate(int

times)

times^ is the number of times

โ€˜*โ€™^ is printed^

on one line.

-^ Test the method by making a call to

replicate^ method in the main program like this:

replicate(25) What shows up on the screen?

A 4ร—25 โ€“ rectangle of stars โ€ข In the main program, use the

replicate method in a loop to print a 4-row rectanglewith 25 โ€˜*โ€™ symbols in each row:^ *************************^ *************************^ *************************^ *************************

Replicating

any^ character

-^ Add^ a third function^ replicate(char symbol, int times)^ that prints a character

symbol^ a specified number^ times

times.

  • Modify the main function to call

replicate

with parameter-values

โ€˜#โ€™^ and^5

respectively:^ replicate(โ€˜#โ€™, 5) ; What prints?

An^ m ร— n^

  • rectangle of characters
    • Modify the main program to print an

m ร— n โ€“

rectangle of a specified symbol (see dialogbelow): Number^ of

rows:^2 Number^ of

columns:

Character

to^ print:

x xxxxxxx xxxxxxx

Test to print more rectangles โ€ข Using the above, last function, can you similarly print a3x20 โ€“ rectangle of โ€˜

*โ€™ characters? ******************** ******************** ********************

-^ How about printing a 3x4 โ€“ rectangle of โ€˜

#โ€™ characters?

####