Skip to content

Instantly share code, notes, and snippets.

@theniceboy
Last active July 9, 2022 05:00
Show Gist options
  • Save theniceboy/368b1f718c881ca746744f30d99a564b to your computer and use it in GitHub Desktop.
Save theniceboy/368b1f718c881ca746744f30d99a564b to your computer and use it in GitHub Desktop.
Practice problem #1

Printing triangles

Part I

Write the function repeatString that takes a String and an integer, and returns a String built by repeating the given String given number of times.

For example, one should be able to call

print(repeatString("*", 10));

and get

**********

as the output.

Hint

You can add to Strings together by:

String a = "Hello, ";
String b = "Alina";
print(a + b); // It'll print out "Hello, Alina"

Part II

Use the printString function you wrote along with a for loop to print out this 6x6 triangle:

*
**
***
****
*****
******

Part III (Optional)

Use the printString function you wrote along with a for loop to print out this triangle:

*******
 *****
  ***
   *
@theniceboy
Copy link
Author

You don’t. You want to call repeatString function multiple times every loop cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment