Wednesday, 6 September 2017

last string should come first. Should use RECURSION

String str = "Blog spots welcomes you friends";
    String temp = "";
    String finalString = "";
        for(int i =str.length()-1;i>=0;i--){
            temp +=i!=0?str.charAt(i):str.charAt(i)+" ";
            if(str.charAt(i) == ' '||i==0){
                for(int j=temp.length()-1;j>=0;j--){
                    finalString += temp.charAt(j);
                }
                temp = "";
            }
        }
            System.out.println(finalString);
    }
}

No comments:

Post a Comment

test your brain

https://www.youtube.com/watch?v=bEU9dkOG7co&feature=youtu.be