In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the do while statement in Java". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use the do while statement in Java"!
do-while syntax analysis
Let's start by understanding the do-while syntax:
do { // statements} while (expression);
Note: The last semicolon cannot be omitted, otherwise it will prompt compilation error.
do-while use scenario
After many searches and consultations, I finally found two relatively satisfactory use scenarios. Let's look at them together.
Use scenario 1: grab tickets
For the ticket-snatching business, regardless of 37 21, first snatch and then judge whether the ticket-snatching is successful. If the ticket-snatching is successful, exit the loop, otherwise continue to execute the ticket-snatching. The pseudo-code implemented is as follows:
do { //Ticket code...} while (failed to get tickets);
Usage scenario: binary conversion
After a lot of searching, it is found that in the JDK source code, there are also a small number of scenarios using do-while, such as Integer binary conversion, the relevant source code is as follows:
static int formatUnsignedInt(int val, int shift, char[] buf, int offset, int len) { int charPos = len; int radix = 1 >>= shift; } while (val != 0 && charPos > 0); return charPos;}
For example, decimal conversion to binary will perform this method. In the business of binary conversion, no matter what, at least one binary conversion will be performed, so this business scenario is very suitable for do-while.
At this point, I believe that everyone has a deeper understanding of "how to use the do while statement in Java," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.