In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the knowledge points of Java selection structure and cycle structure". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. selection of structure
Make a logical judgment according to the known conditions, and perform the response operation when the conditions are met.
1.1 basic if selection structure 1.1.1 Syntax if (Boolean expression) {/ / Code Block} 1.1.2 execution flow
Judge the Boolean expression:
If the result is true, execute the code block, and execute the subsequent code after the execution is complete
If the result is false, the code block will not be executed and the subsequent code will be executed
1.1.3 the code shows public class Demo1 {public static void main (String [] args) {if (1judgment 1) {System.out.println ("judged correctly");} System.out.println ("Program ends");} 1.1.4 run result
Judge correctly
The program runs at the end
1.2 balance if selection structure 1.2.1 Syntax if (Boolean expression) {/ / Code Block 1} else {/ / Code Block 2} 1.2.2 execution flow
Judge the Boolean expression:
If the result is true, execute block 1, exit the entire selection structure, and execute subsequent code
If the result is false, execute block 2, exit the entire selection structure, and execute subsequent code
1.2.3 the code shows public class Demo1 {public static void main (String [] args) {int score=79; if (score > 60) {System.out.println ("Congratulations, passing grades");} else {System.out.println ("Unfortunately, failing grades") } System.out.println ("exit the program.");} 1.2.4 run result
Congratulations on passing the grade.
Exit the program.
1.3 repeat if selection structure 1.3.1 Syntax if (Boolean expression 1) {/ / Code Block 1} else if (Boolean expression 2) {/ / Code Block 2}... Else if (Boolean expression n) {/ / Code Block n} else {/ / Code Block naugh1} 1.3.2 execution flow
Judge Boolean expression 1:
If Boolean expression 1 turns out to be true, execute block 1, exit the entire selection structure, and execute subsequent code
If Boolean expression 1 results in false, Boolean expression 2 is judged:
If Boolean expression 2 turns out to be true, execute block 2, exit the entire selection structure, and execute subsequent code
If the result is false...
If all expressions are false, execute the execution block Number1, exit the entire selection structure, and execute the subsequent code
All if statements are mutually exclusive, as long as one of the Boolean expressions is true and the rest is not executed, it is suitable for interval judgment.
1.3.3 the code shows public class Demo1 {public static void main (String [] args) {/ / score
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.