Java 3_Operators and Switch statement

Relational operators

          /* 
         * > : Greater Than
         * < : Less Than
         * == : Equal To
         * != : Not Equal To
         * >= : Greater Than Or Equal To
         * <= : Less Than Or Equal To
         */

Logical operators

         /* 
         * ! : Converts the boolean value to its right to its opposite form ie. true to false
         * & : Returns true if boolean value on the right and left are both true (Always evaluates both boolean values)
         * && : Returns true if boolean value on the right and left are both true (Stops evaluating after first false)
         * | : Returns true if either boolean value on the right or left are true (Always evaluates both boolean values)
         * || : Returns true if either boolean value on the right or left are true (Stops evaluating after first true)
         * ^ : Returns true if there is 1 true and 1 false boolean value on the right or left
         */

Switch statement

char theGrade = 'B';
        /* 
         * default code is executed if there are no matches
         * You are not required to use the break or default statements
         * The expression must be an int, short, byte, or char
         */
        switch (theGrade)
        {
        case 'A':
            System.out.println("Great Job");
            break; // Ends the switch statement
        case 'B':
            System.out.println("Good Job, get an A next time");
            break;
        case 'C':
            System.out.println("OK, but you can do better");
            break;
        default:
            System.out.println("You failed");
            break;
        }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容