A bit is my study, found and learned some of the methods, the great gods have a lot of guidance:
1, using JS to achieve, this personal method feels more direct
1 //js for reverse output2<script type= "Text/javascript" >3$(function(){4Alert (1)5 6 varstr = ' You are a big bad man ';7 varNewstr = Str.split (""). Reverse (). Join ("");8 alert (NEWSTR);9 })Ten One</script>
2, using the ToCharArray () of the string class to implement the reverse method
1 ImportJavax.swing.JOptionPane;2 3 Public classTest {4 5 //using the ToCharArray () of the string class to implement the reverse method6 Public Static voidMain (string[] args) {7 String orgstring;8String resultstring = "";9 //pop-up box prompt messageTenOrgstring =joptionpane.showinputdialog ("Please enter content that needs to be reversed!") "); One Char[] chararray=Orgstring.tochararray (); A for(inti = chararray.length-1; I >=0; i--) { -resultstring+=Chararray[i]; - } theJoptionpane.showmessagedialog (NULL, resultstring, "Reverse String", joptionpane.information_message); - } - -}
3, using the substring () method provided by the String class plus recursion
1 import Javax.swing.JOptionPane;2 3 Public class Test {4 5 //using the substring () method provided by the string class plus recursion6 7public staticvoidresultstring (String str) {8 if(str.length () = = 1) {9 System.out.print (str);Ten}Else { OneString subString1 = str.substring (0, Str.length ()-1); AString subString2 = str.substring (Str.length ()-1); - System.out.print (subString2); - resultstring (subString1); the } - } - -public staticvoidMain (string[] args) { + - String originalstring; +originalstring = Joptionpane.showinputdialog ("Please enter content that needs to be reversed:"); A resultstring (originalstring); at - } -}
Using Java or JS to implement string reverse