Sudeep Kumar Das

Input a string from the user. Create a new string called ‘result’ in which you will replace the letter ‘e’ in the original string with letter ‘i’. 

Example : 

original = “eabcdef’ ; result = “iabcdif”

Original = “xyz” ; result = “xyz”

Java Basic Codes

Explanation

1352    0

import java.util.*;

 

public class Strings {

   public static void main(String args[]) {

     Scanner sc = new Scanner (System.in);

     String str = sc.next();

     String result = "";

 

     for(int i=0; i

       if(str.charAt(i) == 'e') {

         result += 'i';

       } else {

         result += str.charAt(i);

       }

     }

 

     System.out.println(result);

   }

}



Share:   

More Questions from Java Basic Codes Module 0