String Word Reverse without Reverse Function

11 08 2014

we have the string = Java programming is fun and we want to reverse that string in each word wise

avaJ gnimmargorp si nuf ,without using any reverse function.

/**
* @author TechSivam
* Reverse the string each word and not to use any string reverse methods.
*/
public class StringReverse {
public static void main(String[] args) {
StringBuffer a = new StringBuffer(“Java programming is fun”);
System.out.println(a);

String[] s=a.toString().split(” “);

for (String string : s) {

for (int i = string.length()-1; i >=0; i–) {
System.out.print(string.charAt(i));
}
System.out.print(” “);
}

}

}

 

 

OUTPUT:

Java programming is fun
avaJgnimmargorp si nuf








%d bloggers like this: