In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you how to convert strings to integers in java. The content is simple and clear. I hope it can help you solve your doubts. Let me take you to study and learn this article "how to convert strings to integers in java".
Converts a string to an integer.
This function first discards as many space characters as needed until the first non-space character is found. If the first non-empty character is a positive or negative sign, select the symbol and combine it with as many consecutive numbers as possible, and that part of the character is the value of the integer. If the first non-null character is a number, it is directly combined with subsequent consecutive numeric characters to form an integer.
A string can include extra characters after the characters that form an integer, which can be ignored and have no effect on the function.
No conversion occurs when the first sequence of non-empty characters in a string is not a valid integer, or when the string is empty, or when the string contains only white space characters.
If the function cannot perform a valid conversion, 0 is returned.
Description:
Suppose our environment can only store 32-bit signed integers with a numerical range of [− 231,231 − 1]. If the value exceeds the representable range, it returns INT_MAX (231 − 1) or INT_MIN (− 231).
Example 1:
Enter: "42"
Output: 42
Example 2:
Enter: "- 42"
Output:-42
Explanation: the first non-white space character is'-', which is a negative sign. We try to combine the minus sign with all the consecutive numbers that follow, and we get-42.
Example 3:
Enter: "4193 with words"
Output: 4193
Explanation: the conversion ends with the number'3' because its next character is not a number.
Example 4:
Enter: "words and 987"
Output: 0
Explanation: the first non-empty character is' wicked, but it is not a number or a positive or negative sign. Therefore, a valid conversion cannot be performed.
Example 5:
Enter: "- 91283472332"
Output:-2147483648
Explanation: the number "- 91283472332" exceeds the range of 32-bit signed integers. So INT_MIN (− 231) is returned.
The code is as follows:
What are the advantages of Java. Simple, as long as understand the basic concepts, you can write applications suitable for a variety of situations; 2. Object oriented; 3. Distributed, Java is a network-oriented language; 4. Robust, java provides automatic garbage collection for memory management to prevent programmers from making mistakes when managing memory. ; 5. Security, Java used in the network and distributed environment must prevent the invasion of viruses. 6. Architecturally neutral, as long as the Java runtime system is installed, it can run on any processor. 7. Portability, Java can be easily ported to different machines on the network. 8. Interpretation execution, Java interpreter directly interprets and executes Java bytecode.
The above is about "how to convert strings to integers in java". If this article is helpful to you and think it is well written, please share it with your friends to learn new knowledge. if you want to know more about it, please pay more attention to the industry information channel.
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.