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

How to master Java selection and loop structure

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to master Java selection and loop structure". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to master Java selection and loop structure.

Select structure 1. Simple ifint money=10; if (money > 100) {System.out.println ("money less than 100");}

If in Java is actually the same as other programming languages. Write the data you need to judge in parentheses after if, and execute it if you match it.

two。 Multiple if

Multiple if structures, there are many choices, but choose one here with else if to use

If (number==1) {System.out.println ("you chose toothpaste, 10 ¥"); shop = 10;} else if (number==2) {System.out.println ("you chose towels, 15 ¥"); shop = 15 } else if (number==3) {System.out.println ("you chose a washbasin, 20 ¥"); shop = 20;} else {System.out.println ("wrong choice"); a = false;}

When multiple judgments are needed, just after the closing parentheses of the last if, write else if to make the next judgment, and the program will always compare, such as after the execution of all the if that has not yet been met, execute the else statement, for example, the code above allows you to understand deeply, that is, a judgment of the number value.

3. Nested if

As the name implies, the nested if is to write the if in the if. When the program is executed, skip the parent if judgment, and then enter the nested if. If multiple if are nested inside, the execution process is the same.

If (a > 0) {if (a0, match, enter the second if, if a

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