JAVA If conditional statement, switch Multi-branch structure, and logical operator

Source: Internet
Author: User
Tags logical operators

One, if condition statement

Example:

import Java.util.Scanner; Public classtest{ Public Static voidMain (string[] args) {Scannerinch=NewScanner (System.inch); System. out. println ("Please enter student's score:"); intnum =inch. Nextint (); if(num== -) {System. out. println ("Perfect! "); }        Else if(num> -&& num< -) {System. out. println ("qualified! "); }        Else if(num== -) {System. out. println ("just qualified! "); }        Else{System. out. println ("not qualified"); }    }}

The syntax of the IF statement is the same as the javascript,php usage

Multi-nesting support.

Second, switch multi-branch structure

Instance:

ImportJava.util.Scanner; Public classtest{ Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); System.out.println ("Please enter the rank of Fox Punch:"); intnum =In.nextint (); //switch only supports integer (int) or character type (char)        Switch(num) { Case1: System.out.println ("As a martial arts leader!" ");  Break;//Jump                         Case2: System.out.println ("As Wudang Masters!" ");  Break;  Case3: System.out.println ("As an Emei head!" ");  Break; default://defaultSYSTEM.OUT.PRINTLN ("Eviction door! "); }    }}

Third, logical operators

&& is "with", for example: I>1 && i<3, if I is greater than 1 and less than 3 returns True

|| Yes or, for example: i>1 | | I<3, if I is greater than 1, or less than 3 returns True

! Is "non", for example:!i>1, if I is less than 1 returns true

JAVA If conditional statement, switch Multi-branch structure, and logical operator

Related Article

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.