The if statement has three formats, namely: 1. [if (Boolean expression) {execution statement}]; 2. [if (Boolean expression) {execution code} else {execution code}]; 3. [if (Boolean expression) {execution code} else if (Boolean expression) {execution code} else {execution code}].
if statements have three formats, namely:
(recommended learning: java entry program)
1. If statement
if(布爾表達(dá)式){ //如果布爾表達(dá)式為true將執(zhí)行的語句 }
2. Combined with else statement
if(布爾表達(dá)式){ //如果布爾表達(dá)式的值為true }else{ //如果布爾表達(dá)式的值為false }
3. If statement with else if...else statement
if(布爾表達(dá)式 1){ //如果布爾表達(dá)式 1的值為true執(zhí)行代碼 } else if(布爾表達(dá)式 2){ //如果布爾表達(dá)式 2的值為true執(zhí)行代碼 } else if(布爾表達(dá)式 3){ //如果布爾表達(dá)式 3的值為true執(zhí)行代碼 } else { //如果以上布爾表達(dá)式都不為true執(zhí)行代碼 }
(Video tutorial recommended : java video tutorial)
Note:
1. Whether the comparison expression is simple or complex, the result must be of Boolean type.
2. If there is only one statement in the statement body controlled by the if statement, the braces can be omitted; if there are multiple statements, they cannot be omitted. It is recommended that they should never be omitted.
For example:
if(比較表達(dá)式) 語句
3. Generally speaking: there is no semicolon when there is an opening brace, and there is no opening brace when there is a semicolon.
For example:
if(比較表達(dá)式){........}, if(比較表達(dá)式);
For example:
public class HelloWorld { public static void main(String[] args) { int i=10; int j=8; /* * if語句第一種格式 * */ if(i>j){ System.out.println("我是if語句第一種格式"); } /* * if語句第二種格式 * */ if(i<j){ System.out.println("我是if語句第二種格式1"); }else{ System.out.println("我是if語句第二種格式2"); } /* * if語句第三種格式 * */ if(i<j){ System.out.println("我是if語句第三種格式1"); }else if(i>j){ System.out.println("我是if語句第三種格式2"); }else{ System.out.println("我是if語句第三種格式3"); } } }
The output result is as shown in the figure:
The above is the detailed content of What are the formats of if statements?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

QQ email: QQ number@qq.com, English QQ email: English or numbers@qq.com, foxmail email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Tutorial Applicable Model: iPhone13 System: IOS15.3 Version: QQ Mailbox 6.3.3 Analysis 1QQ mailbox has four formats, commonly used QQ mailbox: QQ number@qq.com, English QQ mailbox: English or numbers@qq.com, foxmail Email account: set up your own account@foxmail.com, mobile phone email account: mobile phone number@qq.com. Supplement: What is qq mailbox? 1 The earliest QQ mailbox was only between QQ users

ink is the file format of a shortcut; a shortcut is a file object that is similar in function to a symbolic link, but is essentially different from a symbolic link; a shortcut is an ordinary file, not a symbol, and its extension is ".lnk" , so the shortcut can be copied, moved, changed or deleted; the shortcut can point to a file, folder or any other legal location in the system.

The kgma format is a special format developed by Kugou to protect music copyright. It is a specialized protection format that can only be played on Kugou music players. It is an encrypted package of the MP3 format. Due to music copyright issues, music The file is encrypted and does not support format conversion for the time being. It can only be played on Kugou Music.

In iOS 17 and macOS Sonoma, Apple has added new formatting options for Apple Notes, including block quotes and a new Monostyle style. Here's how to use them. With additional formatting options in Apple Notes, you can now add block quotes to your notes. The block quote format makes it easy to visually offset sections of writing using the quote bar to the left of the text. Just tap/click the "Aa" format button and select the block quote option before typing or when you are on the line you want to convert to a block quote. This option applies to all text types, style options, and lists, including checklists. In the same Format menu you can find the new Single Style option. This is a revision of the previous "equal-width"

In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

CR3 files are original raw files recorded by Canon's new cameras using the Digic8 image processor. cr3 files can be opened through Canon ddp, which is software for performing image adjustments such as "RAW development" on RAW images.

The latest iPhone Pro series is equipped with a powerful 48MP sensor that ensures highly detailed and crystal clear photos to capture every precious moment. However, one potential drawback is the size of full-resolution images, especially those in ProRAW format. Although the maximum storage space offered by the iPhone is 512GB, capturing a lot of ProRAW images (about 75MP each) and video (440MB per minute, 60FPS) can quickly eat up your storage space. This can cause problems if you plan to use your iPhone as your main camera for large projects or travel. But wouldn't it be great if you could take those high-resolution 48MP photos without worrying about storage limitations? it's quick

pptm is a file format of PowerPoint in the office office suite. Its full name is "macro-enabled PowerPoint presentation". pptm files can only be opened with office software of version 2007 and above. If opened with other versions of software, problems such as inability to edit and incomplete images will occur.
