
how to reverse a string without changing its place

Hi Friend,
Another way of reversing string:
import java.util.*;
public class ReverseString{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.nextLine();
String str[]=st.split("");
String reversedSt="";
for(int i=str.length-1;i>=0;i--){
reversedSt+=str[i];
}
System.out.println("Reversed String is: "+reversedSt);
}
}
Thanks

public class reverse {
public static void main(String args[])
{
StringBuffer s=new StringBuffer("Java is interesting");
System.out.println("Before reversing the string :"+s);
s=s.reverse();
System.out.println("After Reverse string is :"+s);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.