Reverse Strings - Problem Description
Reverse Strings - Problem Description
Problems for exercises and homework for the "Programming Fundamentals" course @ SoftUni.
You can check your solutions in Judge.
1. Reverse Strings
You will be given a series of strings until you receive an "end" command. Write a program that reverses strings and
prints each pair on a separate line in the format "{word} = {reversed word}".
Examples
Input Output
Solution
Use while loop and read strings until you receive "end".
Reverse the String with for loop. Start from the last index and append each symbol to the new String.
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Examples
Input Output
work workworkworkwork
ball ballballballball
Solution
Read a string array.
Initialize StringBuilder.
Iterate through elements in the array. Find the length of the word at each iteration and append it to the
StringBuilder.
3. Substring
On the first line, you will receive a string. On the second line, you will receive a second string. Write a program that
removes all of the occurrences of the first String in the second until there is no match. At the end, print the
remaining String.
Examples
Input Output Comment
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
4. Text Filter
Write a program that takes a text and a string of banned words. All words included in the ban list should be
replaced with asterisks "*", equal to the word's length. The entries in the ban list will be separated by a comma and
space ", ".
The ban list should be entered on the first input line and the text on the second input line.
Examples
Input Output
Linux, Windows It is not *****, it is GNU/*****. *****
It is not Linux, it is GNU/Linux. Linux is merely the kernel, while GNU adds the
is merely the kernel, while GNU adds the functionality. Therefore we owe it to
functionality. Therefore we owe it to them by calling the OS GNU/*****!
them by calling the OS GNU/Linux! Sincerely, a ******* client
Sincerely, a Windows client
Hints
Read the input.
Replace all ban words in the text with an asterisk (*).
o Use the built-in method replace(banWord, replacement).
Examples
Input Output
Agd#53Dfg^&4F53 53453
AgdDfgF
#^&
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Hints
Read the input.
Use a loop to iterate through all characters in the text. If the char is a digit, print it, otherwise, ignore it.
o Use Character.isDigit(char symbol)
Do the same for the letters and other chars.
o Find something like isDigit method for the letters.
© SoftUni Global – softuni.org. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.