I have to write a code with two classes, one reverses a string changing positions e.g
I love you
becomes uoy evol I
and the other class reverses the string without changing positions e.g
I love you
becomes I evol uoy
.
I have a small code but I have failed to get a way if calling the methods in those classes.
What I have now is just the code that reverses the string in the first way. Any help is welcome.
class StringReverse2{
public static void main(String[] args){
String string="I love you";
String reverse = new StringBuffer(string). //The object created through StringBuffer is stored in the heap and therefore can be modified
reverse().toString(); //Here the string is reversed
System.out.println("Old String:"+string); //Prints out I love you
System.out.println("New String : "+reverse);//Prints out the reverse that is "uoy evol I"
}
}