JAVA if Condition Statement, switch multi-branch structure, and logical operators, switch operators

Source: Internet
Author: User

JAVA if Condition Statement, switch multi-branch structure, and logical operators, switch operators

I. if condition statements

Example:

Import java. util. role; public class Test {public static void main (String [] args) {role in = new role (System. in); System. out. println ("Enter the student's score:"); int num = in. nextInt (); if (num = 100) {System. out. println ("full score! ");} Else if (num> 60 & num <100) {System. out. println (" qualified! ");} Else if (num = 60) {System. out. println (" just qualified! ") ;}Else {System. out. println (" unqualified ");}}}

The syntax of the if statement is the same as that of javascript and php.

Multiple Nesting is supported.

 

Ii. switch multi-branch structure

Instance:

Import java. util. role; public class Test {public static void main (String [] args) {role in = new role (System. in); System. out. println ("Enter the ranking of Linghu Chong:"); int num = in. nextInt (); // switch only supports INTEGER (int) or character type (char) switch (num) {case 1: System. out. println ("as the martial arts leader! "); Break; // jump out of case 2: System. out. println (" head of Wudang! "); Break; case 3: System. out. println (" head of Emei! "); Break; default: // default System. out. println (" eviction! ");}}}

 

Iii. logical operators

& Is "and"-> For example: I> 1 & I <3. If I is greater than 1 and less than 3, true is returned.

| Yes "or"-> For example: I> 1 | I <3. If I is greater than 1 or less than 3, true is returned.

! Is "not"-> example :! I> 1. If I is less than 1, true is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.