In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the control structures in java". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the control structures in java"?
Control structure in java:
Conditional structure here are mainly some if,if else conditional statements to control the flow of the code, needless to say. Loop control structure for cycle while cycle do while cycle
1. While and do while
While and do while loops are relatively simple compared to for, and they are used in the same way as the C language, so I won't talk too much about them here. The style is shown below.
While (bool expression) {} do {} while (bool expression)
The do while expression is special in that it is executed at least once.
2. For cycle structure
General for loop structure
For (initialization; Boolean expression; condition update) {/ / Code statement}
Let's take an example.
Public class for_t {public static void main (String [] args) {for (int I = 0; I < 10; iTunes +) {System.out.printf ("I =% d\ n", I);}
The following test results should be known to everyone. It's too easy. That's it.
I = 0i = 1i = 2i = 3i = 4i = 5i = 6i = 7i = 8i = 9
VIP for cycle structure
This usage has been encountered before when learning other object-oriented languages. Maybe I haven't programmed in an object-oriented language for a long time, but I look a little new here. It is used in the following format
For (child elements: collection of elements) {}
Points to pay attention to:
The type of the child element should be the same as the type of the element collection, otherwise an error will be compiled. Such a loop iterates through all the elements in the collection of elements, and we need to use break and continue in the body of the loop to deal with which one needs to be processed and which one doesn't.
Public class for_vip {public static void main (String [] args) {int [] money = {2000, 3000, 4000, 5000}; for (int I: money) {System.out.printf ("I =% d\ n", I);} String [] name = {"arm", "intel", "qulcom", "sprd"}; for (String na: name) {System.out.printf ("name:%s\ n", na.toString ());}}
Experimental results:
I = 2000I = 3000I = 4000I = 5000name:armname:intelname:qulcomname:sprd
At this point, I believe you have a deeper understanding of "what are the control structures in java?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow 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.