Thursday, 4 May 2017

Array - Split reverse

  Given a string (array of character), split the string to half and reverse each half Input: Input String: "Mike" Output: "iMek" Input String: "break" Output: "rbeka"



 public String func(String str)
    {
        // write your code here
        try{
            int len=str.length(),length;
            String result="";
            length=(len/2)-1;
            for(int i=length;i>=0;i--)
            {
             result=result+str.charAt(i);
            }
            if(len%2!=0)
            {
             result=result+str.charAt(len/2);
            for(int i=len-1;i>length+1;i--)
            {
                result=result+str.charAt(i);
            }}
        else{
            for(int i=len-1;i>length;i--)
            {
                 result=result+str.charAt(i);
            }
            }
            return result;
        }
        catch (Exception e)
        {
            String s="NULL";
            return s;
        }
   
    }

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

1 comment:

  1. Betway Casino Resort - MapyRO
    Located 영주 출장안마 just five minutes from New Orleans' Boardwalk, the Betway 여주 출장샵 Casino Resort is a Native 삼척 출장마사지 American gaming destination featuring an 통영 출장마사지 all-new 구미 출장마사지 gaming experience.

    ReplyDelete

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