If-else

Used to determine whether the given conditions are met, and decide which operation to perform based on the result of the determination (true or false)

  • Definition:
> if (condition 1) {

> If condition 1 is true, execute this

> }else if(condition2){

> If condition 2 is true, execute this

> } else {

> If neither condition 1 nor condition 2 is true, execute this

> }

Note: There must be if and else control statements in the if control statement, and there can be 0 or more else if statements, which are used according to the actual scene

  • Example:
> String str = "fxiaoke"

> if(str. contains("s")) {

> str = "hello"

> }else if(str. contains("f")){

> str = "welcome"

> } else {

> str = "hi"

> }//final result str=welcome
2024-07-12
0 0