Search results
Sep 10, 2017 · Since the below method (using XOR) to reverse a string is not listed, I am attaching this method to reverse a string. The Algorithm is based on : 1.(A XOR B) XOR B = A . 2.(A XOR B) XOR A = B. Code snippet:
The function takes the first character of a String - str.charAt(0) - puts it at the end and then calls itself - reverse() - on the remainder - str.substring(1), adding these two things together to get its result - reverse(str.substring(1)) + str.charAt(0)
Mar 14, 2010 · You said you don't want to do it the easy way, but for those Googling you should use StringBuilder.reverse: ...
May 14, 2009 · I have been messing around with recursion today. Often a programming technique that is not used enough. I set out to recursively reverse a string. Here's what I came up with: //A method to revers...
Aug 2, 2016 · Use StringBuilder class or StringBuffer class they have already a method reverse() for reversing the string ...
Mar 6, 2018 · You can use this to reverse the string, you don't need to use your own method. new StringBuilder(word).reverse().toString() If you want to use your solution you must change int j = a.length() to int j = a.length() -1;
Aug 9, 2017 · Strip them from the string, and determine whether the string that remains is a palindrome. Take the answer for this smaller string and use it as the answer for the original string then repeat from 1. The only string manipulation is changing the string to uppercase so that you can enter something like 'XScsX'
Nov 27, 2017 · Given a string like. String str = "Aniruddh"; the idiomatic solution is. String reversed = new StringBuilder(str).reverse().toString();
Can anyone tell me how to write a Java program to reverse a given sentence? For example, if the input is: "This is an interview question" The output must be: "question interview an is this"
Nov 7, 2014 · First, you could use Arrays.toString(Object[]) to print your String[].Then you can iterate half of the array and swap the String at the current position with it's corresponding pair (at the length - current index, remembering that Java arrays are zero indexed so the last position in an array is array.length - 1).