10 Silly Strings

Task 1 – Concatenation

Write a program that asks a user to enter two separate strings together before output them as a single string.

Task 1a – Length

Modify the program above so you output the length of the new string

Task 2 – Substring

Write a program that returns a Substring of length 10 characters.   Assuming your string is longer than 10 characters can you output the first, last or middle 10 characters?

Task 3a – Looping Lettings

Write a program that outputs each letter of a string on a new line with no other text to accompany it i.e I want you to isolate each letter in a string.

Task 3b – Looping Lines

Modify the program so that it splits a sentence into words and outputs each word on a separate line.

To complete this task you will need to look at the String.split() method and be able to use a ‘for’ to loop through the array results.

Task 4a – Case Conversion

Write a program that given a mixed case sentence outputs upper and lower case versions.  The program should be dynamic so that the user can enter a string. Example Output:

  • You entered: Once Upon A Time
  • lowercase: once upon a time
  • UPPERCASE: ONCE UPON A TIME 

Task 4b – Case Queries

Write a program that only outputs lowercase letters of a string.  Hint – it will need an IF statement.

Task 5a – Search and Replace

Write a function called SearchAndReplace which takes three arguments: a string of any length and two single-character strings. The function replaces all occurrences of the second argument with the third argument and returns the result. For example:

  • SearchAndReplace(“Pat a cake”, “a”, “o”) should return “Pot o coke”.

It is not acceptable in this question to use the built in str_replace function that many languages now provide!

Task 5b – Multiple Search and Replace

An interesting challenge here is to consider allowing the second and third arguments to be strings of any length. For example, what should SearchAndReplace(“Baaad”,”aa”,”oo”) give?)

Task 5c – Regular Replace

Modify the program so it removes all non alphanumeric characters e.g. A12&!FT would return A12FT

Task 6a – Vowels

Write a program that only outputs the vowels in a string

Task 6b – Replace Vowels

Write a program that replaces all the vowels in a word with a dash (-).  You should use a String.replace() method. Note: you will need to call replace more than once to remove all vowels unless you complete the extension.

Task 7 – Purals

Write a program that takes a word and returns its plural version.

If you are not sure on the plural rules then check out http://bit.ly/VJ416z

Task 8a  – ASCII Convertor

Write a program that outputs the ASCII values that represent each character in the string

Task 8b – Binary Characters

Outputs the binary equivalent of each character in a string

Task 9 – Frequency Analysis

Write a program that find the Number of Vowels and Consonants in a string.  

Modify the program so it find the Frequency of Characters in a String

Task 10 – Surprise Strings

About CDB 362 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.