程序猿的读书笔记

Java 3_Operators and Switch stat

2018-09-02  本文已影响0人  綿綿_

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;
        }
上一篇 下一篇

猜你喜欢

热点阅读