Java Fundamentals 3

Source: Internet
Author: User
Tags logical operators

First, basic if structure

1. Flowchart

Input/Output

Judging and branching

Process Line

1.1 Simple if condition to judge

if (expression) {

The expression is true to execute the code in {}

}

1.2 Simple if condition to judge

if (expression) {

Expression is true, execute here

}else{

The expression is false, this line here

}

Description: If the If or else is followed by, and there is only one line of code, {} can be omitted, but it is not recommended to omit

Second, logical operators

L && Logic and (press shift+7)--and (and, at the same time)

Multiple conditions, 1 are false, if () all false, multiple conditions are true at the same time, if () is true

L | | (Press shift+ to enter the above |) -or (OR)

Multiple conditions, as long as 1 are true, if () all is true

! (in English state)--take the inverse not equal to! =

L Determine if strings are equal

A, case-sensitive: password

String variable. Equals (the value of a string or a string variable)

B, case-insensitive: Verification Code

String variable. Equalsignorecase (Value of string or string variable)

How do I break down numbers in bits, 10, hundred, thousand? "P47"

Int digit = number% 10//decomposition get single digit

Int 10 bit = number/10 10//decomposition get 10 digits

Int hundred = number/100% 10//decomposition to get the number of hundred

INT thousand = number/1000% 10//Decomposition get thousand

Third, multiple if structure

Copy Code

Copy code if (condition 1) {//code block}else if (condition 2) {//code block}else if (condition N) {//code block} else{/code block}

Copy Code

Copy Code

Description: An else if can have multiple, sequential requirements on the number range

Enter String--if in if (variable name. Equals ("string")) {}

Iv. Nested IF structures

if (condition 1) {//code block I f (condition 1-1) {} Description: The If structure can be a structure such as if, if...else, multiple if, etc.} else{can be if, if...else, multiple if and other structures}

V. Switch structure

Switch structure using the occasion:

int \char 2 types of equivalence judgment to use

The similarities and differences between the switch structure and the IF structure

Same point: equal judgment can be achieved

Different points:

1. Different syntax

2. The use of different occasions

3. If structure, focusing on range judgment

4. Switch structure, focusing on equivalence judgment, type can only be int, char type

5. Efficiency:

In the equivalence judgment, the switch structure efficiency is higher than the IF structure

Vi. exception handling--hasnextint ();

Determines whether an integer

if (Input.hasnextint ()) {//Boolean type

code block

}

Java Fundamentals 3

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.