Thursday, 4 May 2017

Array - Shuffle merge

 Given a input two string (inputStr1) and (inputStr2), merge these two string by combining elements of same index Input String: "Hello" Deletion String: "123" Output String: "H1e2l3lo"


@Override
public String func (String inputStr1, String inputStr2){


                 if(inputStr1==null)
                 {
                     return inputStr2;
                 }
                 else if(inputStr2==null)
                 {
                     return inputStr1;
                 }
         try{
         int k=inputStr1.length();
         int l=inputStr2.length();int p,t,m=0;
        
                 String output="";
                 if(k>l){p=k;t=l;}else{p=l;t=k;m=1;}
          
         for(int i=0;i<p;i++)
         {
                   if(i<t)
                     {
                       output=output+inputStr1.charAt(i)+inputStr2.charAt(i);
                     }
                  else if(m==0)
                     {
                       output=output+inputStr1.charAt(i);
                     }
                  else
                     {
                       output=output+inputStr2.charAt(i);
                     }
         }
         return output;
         }
         catch(Exception e){
         
        return "NULL";
        }
    
    
   }
}

Visit : https://c-programs-world.blogspot.in for more question

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Blog Archive

Powered by Blogger.

Sample Text

Array - Shuffle merge

  Given a input two string (inputStr1) and (inputStr2), merge these two string by combining elements of same index Input String: "He...

Followers

Search This Blog

Ordered List

Theme Support