/*
分支結構中的if-else (條件判斷結構)
一、三種結構
第一種:
if(條件表達式){
}
分支結構中的if-else (條件判斷結構)
一、三種結構
第一種:
if(條件表達式){
}
第二種:
if(條件表達式){
執行表達式1
}else{
執行表達式2
}
第三種 多選一
if(條件表達式){
執行表達式1
}else if(條件表達式){
執行表達式2
}
else if(條件表達式){
執行表達式3
}
...
else{
執行表達式n
}
*/
if(條件表達式){
執行表達式1
}else{
執行表達式2
}
第三種 多選一
if(條件表達式){
執行表達式1
}else if(條件表達式){
執行表達式2
}
else if(條件表達式){
執行表達式3
}
...
else{
執行表達式n
}
*/
class IfTest
{
public static void main(String[] args)
{
//舉列1
int hearBeats =79;
if(hearBeats<60||hearBeats>100){
System.out.println("需要做進一步檢查");
}
System.out.println("檢查結束");
{
public static void main(String[] args)
{
//舉列1
int hearBeats =79;
if(hearBeats<60||hearBeats>100){
System.out.println("需要做進一步檢查");
}
System.out.println("檢查結束");
//舉列2
int age=23;
if(age<18){
System.out.println("你可以看動畫片");
}else{
System.out.println("你可以就看電影了");
}
int age=23;
if(age<18){
System.out.println("你可以看動畫片");
}else{
System.out.println("你可以就看電影了");
}
//舉列3
if(age<0){
System.out.println("您輸入的數據非法");
}else if(age<18){
System.out.println("青少年時期");
}else if(age<35){
System.out.println("青壯年時期");
}else if(age<60){
System.out.println("中年時期");
}else if(age<120){
System.out.println("老年時期");
}else{
System.out.println("你是要成仙啊~~~~");
}
}
}
if(age<0){
System.out.println("您輸入的數據非法");
}else if(age<18){
System.out.println("青少年時期");
}else if(age<35){
System.out.println("青壯年時期");
}else if(age<60){
System.out.println("中年時期");
}else if(age<120){
System.out.println("老年時期");
}else{
System.out.println("你是要成仙啊~~~~");
}
}
}