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

The usage of if statement in Java

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "the usage of if sentence of Java". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the usage of if sentences in Java".

1. If statement format 1

~ java

(1) format:

If (relational expression) {

Sentence style

}

~ ~

(2) execute the process:

① first calculates the value of the relational expression

② executes the statement body if the value of the relational expression is true

③ does not execute the statement body if the value of the relational expression is false

④ continues to execute the following statements.

(3) specific examples:

2. If statement format 2

~ java

(1) format:

If (relational expression) {

Sentence aspect 1

} else {

Sentence style 2

}

~ ~

(2) execute the process:

① first calculates the value of the relational expression

② executes body 1 if the value of the relational expression is true

③ executes statement body 2 if the value of the relational expression is false

④ continues to execute the following statement

(3) specific examples:

3. If statement format 3

~ java

(1) format:

If (relational expression 1) {

Sentence aspect 1

} else if (relational expression 2) {

Sentence style 2

}

...

Else {

Sentence style nasty 1

}

~ ~

(2) execute the process:

① first calculates the value of relational expression 1

② executes statement body 1 if the value is true; if the value is false, the value of relational expression 2 is evaluated

③ executes statement body 2 if the value is true, and evaluates the value of relational expression 3 if the value is false

④...

If the ⑤ does not have any relational expression of true, it executes the body of the statement Number1.

(3) specific example: enter the number of days of a week on the keyboard, and output the corresponding Monday, Tuesday,. Sunday

At this point, I believe you have a deeper understanding of "the use of if sentences 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.

Share To

Development

Wechat

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

12
Report