class
apples{
public
static
void
main(String args[]){
int
boy, girl;
boy
= 18;
girl
= 68;
if(boy
> 10 && girl < 60){
System.out.println("You
can enter");
}else{
System.out.println("You
can not enter");
}
}
}
if(boy
> 10 && girl < 60)
在同一時間,我們需要比較兩個語句:
&&意味著兩個條件必須在同時乎合
| |這意味著兩個條件,如果有一說法是乎合的,然後執行它!
&&意味著兩個條件必須在同時乎合
| |這意味著兩個條件,如果有一說法是乎合的,然後執行它!
因為boy是大於10,但girl不小於60,這樣的聲明是假的,然後將執行:
else{
System.out.println("You
can not enter");
}
因此,屏幕上會顯示:
You
can not enter
但是,如果(boy>
10| |girl<60){因為boy是大於10,所以這種說法是真實的,所以然後會執行:
System.out.println("You
can enter");
因此,屏幕上會顯示:
You
can enter
沒有留言:
張貼留言