The method:
public void Convertstr (String str) {
Convert a String object to a StringBuffer class object that can be changed
Then call the reverse () method of the StringBuffer class to implement the inversion
String strreverse=new stringbuffer (str). reverse (). toString ();
System.out.println (StrReverse);
}
Other methods:
public void Convertstr (String str) {
for (int i=str.length () -1;i>=0;i--)
{
Output one character per reverse
System.out.print (Str.charat (i));
}
}
A less desirable approach: trouble
public void Convertstr (String str) {
String strnew= "";
String [] s=new string[str.length ()];
for (int x=0;x<str.length (); x + +)
{
S[x]=str.substring (x,x+1);
}
for (int x=str.length () -1;x>=0;x--)
{
STRNEW+=S[X];
}
System.out.println (strnew);
}
Test:
public class Exchange {
public static void Main (string[] args) {
String str= "ABC";
New Exchange (). CONVERTSTR (str);
}