[Java]流程控制


 class TestVar2{

    public static void main(String[] args){

        int x=5;

        int y;

        if(x>4){

            y=6;

        }

        System.out.println(y); //產生錯誤,y沒有初始化

    }

}


 class TestVar2{

    public static void main(String[] args){

        final int x=5;

        int y;

        if(x>4){

            y=6;

        }

        System.out.println(y); //x為常數,所以if直接成立

    }

}


 class TestVar2{

    public static void main(String[] args){

        int x=5;

        int y;

        if(x>4){

            y=6;

        }

        else{

              y=7;

        }

        System.out.println(y); //y最後都會有值

    }

}

留言

這個網誌中的熱門文章

[HTML]標籤-下

論P, NP, NP-Complete, NP-Hard問題

[Python]基礎課程

[系統]解除電腦限制頻寬

[HTML]標籤-上

[AlaSQL] 多data查詢+累計

How to Check the MySQL Version

[SQL Sever] 日期時間

推薦使用的9款編程字體

類別型態 vs 基本型態