W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
第一個決策語句是 if 語句。這種說法的一般形式是 -
if(condition) { statement #1 statement #2 ... }
這個語句的一般工作是首先在 if 語句中評估一個條件。如果條件為真,它然后執(zhí)行語句。下圖顯示了 if 語句的流程。
下面是一個if / else語句的例子 -
class Example { static void main(String[] args) { // Initializing a local variable int a = 2 //Check for the boolean condition if (a<100) { //If the condition is true print the following statement println("The value is less than 100"); } } }
在上面的例子中,我們首先將一個變量初始化為值2.然后我們評估變量的值,然后決定是否應(yīng)該執(zhí)行 println 語句。上面的代碼的輸出將是 -
The value is less than 100
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: