Home > Computer Programming > Problems involving strings

Problems involving strings

September 11, 2012 Leave a comment Go to comments

Write a method stringSpace that takes a string s and returns s, spaced out:

  • Call: stringSpace(“Hello”);
  • Return value: H e l l o

Adapt your code so that the method takes a string s and an int n so that it returns s spaced out with n spaces:

  • Call: stringSpace(“Hello”, 3);
  • Return value: H   e   l   l   o

Adapt your code so that the method now takes a string s, an int n and a string c so that it returns s spaces out with n instances of c:

  • Call: stringSpace(“Hello”, 2, “*”);
  • Return value: H**e**l**l**o

Write a method stringReverse that takes a string s and returns s reversed:

  • Call: stringReverse(“Hello”);
  • Return value: olleH
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s