In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how java uses the stack to reverse characters. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Use the stack
Package net.javaguides.corejava.string;import java.util.Stack;/*** * @ author Ramesh Fadatare**/public class ReverseStringUsingStack {/ / Function to reverse a string in Java using a stack and character arraypublic static String reverse (String str) {/ / base case: if string is null or emptyif (str = = null | | str.equals (")) return str;// create an empty stack of charactersStack
< Character >Stack = new Stack
< Character >(); / / push every character of the given string into the stackchar [] ch = str.toCharArray (); for (int I = 0; I < str.length (); iSum +) stack.push (ch [I]); / / start from index 0int k = 0 stack.isEmpty / pop characters from the stack until it is emptywhile (! stack.isEmpty ()) {/ / assign each popped character back to the character arraych [kicking +] = stack.pop ();} / / convert the character array into string and return itreturn String.copyValueOf (ch) } public static void main (String [] args) {String str = "javaguides"; str = reverse (str); / / string is immutableSystem.out.println ("Reverse of the given string is:" + str);}}
Output:
Reverse of the given string is: what are the basic data types of sediugavajjava? the basic data types of Java can be divided into: 1. Integer types, which are used to represent the data types of integers. 2. Floating point type, which is used to represent the data type of decimals. 3. Character type. The keyword of character type is "char". 4. Boolean type, which is the basic data type that represents logical values.
Thank you for reading! This is the end of this article on "how java uses stack inversion characters". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.