Click here to Skip to main content
15,943,294 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
double the character 'e'; (help)

examples:

input:-
help

output:-
heelp

input:-
heeeeelp

output:-
heeeeeeeeeelp

What I have tried:

import java.io.*;
import java.util.*;

public class Main {

       static String help(String str)
      {
           // Your code here
		  int a = 0;
		  char ch = 'e';
		  for(int i=0; i<str.length(); i++){
			  if(str.charAt(i)==ch){
				  a = a*ch;
			  }
			  return a.toString();
		  }

		 
		   
			
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str=sc.next();
        String result = help(str);
        System.out.print(result);        
        System.out.println('\n');
    }
}
Posted
Updated 9-Feb-23 1:44am

1 solution

Create an empty 'result string'.
Iterate over the characters of the input string. At each iteration:
append the current character to the result string. If the current character is 'e' then append it another time.

That's all, folks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900