Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the logical structure patterns in Java

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the logical structure patterns in Java", with detailed content, clear steps and proper handling of details. I hope that this article "what are the logical structure patterns in Java" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.

Sequential structure

As the name implies, the sequential structure is executed in the order of the code, which is needless to say.

Branching structure

The branch structure can be subdivided into two:

If... Else... I believe we both know these two words. Translating them into Chinese is what we usually call "if". Just... So how do you use it in Java:

①: if else:

Its basic grammatical structure is as follows:

If (judgment condition) {

Statement 1

} else {

Statement 2

When the judgment condition is true, execute statement 1, otherwise execute statement 2

Example:

Import java.util.*;public class TestDemo13 {public static void main (String [] args) {Scanner scanner = new Scanner (System.in); int n = scanner.nextInt (); if (n > = 5) {System.out.println ("hello");} else {System.out.println ("hehe");}

The meaning of this code is that we enter a number. If the number is greater than or equal to 5 and meets the if condition, execute the statement in our if. If it is not satisfied, execute the following statement.

Note: the parentheses after if can only be Boolean expressions, not mathematical expressions, such as if (5

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report