美文网首页程序猿的读书笔记
Java 3_Operators and Switch stat

Java 3_Operators and Switch stat

作者: 綿綿_ | 来源:发表于2018-09-02 15:08 被阅读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;
        }

相关文章

网友评论

    本文标题:Java 3_Operators and Switch stat

    本文链接:https://www.haomeiwen.com/subject/ukjmwftx.html