Replace the second occurrence of a character

In this program, we will take a string as input and replace the second occurrence of any char with the special character $.

Steps to solve the program
  1. Take a string as input and create an empty string.
  2. Using For loop add each character of the given string to the empty string.
  3. If a character repeats then do not add that character add $ instead.
  4. Print the output.

Output :

calculate the length of a string with loop logic.

swap the last character of a given string.

Leave a Comment