# Java entry if branch switch branch structure, and technical interview with Kwai Tai

Example 3: if Zhang San scores more than 90 points in the Java test, the teacher will reward him with a mobile phone, otherwise the teacher will punish him for squatting.

```if(javaFraction>90) {

System.out.println("The teacher rewarded a mobile phone");

}else{

System.out.println("Punishment squat horse step");

}

```

The flow chart is as follows:

Multiple if selection structure

**1. The condition is divided into several continuous intervals for judgment. A single if selection structure cannot be completed, and multiple if selection structures are troublesome and inefficient.

2. When using multiple if selection structure statements, pay attention to the order**

```if(Condition 1){

//Code block 1

}else if(Condition 2){

//Code block 2

}else if(Condition 3){

//Code block 3

}

```

Example 4: evaluate the test results of the students. The result > = 80 is good, the result > = 60 is medium, and the result < 60 is poor.

```if(score>=80){

System.out.println("The result is good");

}else if(score>=60){

System.out.println("The score is medium");

}else{

System.out.println("Poor grades");

}

```

The flow chart is as follows:

Nested if selection structure

Nested if control statements can enhance the flexibility of the program by writing external and internal statements.

```if(Condition 1){

//Code block 1

if(Condition 2){

//Code block 2

}else{

//Code block 3

}

}esle{

//Code block 4

}

```

Example 5: the factors of children's adult height include heredity, eating habits and physical exercise. The height of a child as an adult is closely related to the height of his parents and his own gender.

Let faHeight be his father's height, moHeight, and the height prediction formula is:

Male adult height = (faHeight + moheight)*0.54

Female adult height = (faHeight * 0.923 +moHeight) / 2

In addition, loving exercise can increase height by 2%, and having good eating habits can increase height by 1.5%. Use the given formula and height prediction method to predict your height.

The height of parents and whether they like physical exercise are required to be input from the keyboard.

Tip: use string comparison Equals method, such as String a = "preferences"; a. The value of equals ("hobby") is true.

```import java.util.Scanner;

public class demo8 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("Please enter your father's height:");

double faHeight = sc.nextDouble();

System.out.println("Please enter your mother's height:");

double moHeight = sc.nextDouble();

System.out.println("Please enter your gender: (male)/(female)");

String sex = sc.next();

System.out.println("Do you like exercise? (yes)/(no)");

String duanlian = sc.next();

System.out.println("Is your diet healthy? (yes)/(no)");

String yinshi = sc.next();

double shengao=0;

//Gender is male

if(sex.equals("male")) {

shengao=(faHeight + moHeight)*0.54;

//Gender is male, love exercise

if(duanlian.equals("yes")) {

shengao=shengao*1.02;

//Gender is male, love exercise, healthy diet

if(yinshi.equals("yes")) {

shengao=shengao*1.015;

}else {

//The gender is male and the diet is healthy

if(yinshi.equals("yes"));

shengao=shengao*1.015;

}

}

//Gender is female

}else if (sex.equals("female")) {

shengao=(faHeight*0.923 + moHeight)*0.54;

//Gender is female, love exercise

if(duanlian.equals("yes")) {

shengao=shengao*1.02;

//Gender is female, love exercise, healthy diet

if(yinshi.equals("yes")) {

shengao=shengao*1.015;

}else {

//The gender is female and the diet is healthy

if(yinshi.equals("yes")) {

shengao=shengao*1.015;

}

}

}

}

System.out.println("Your height is:"+(int)shengao+"cm");

}

}

```

The flow chart is as follows:

switch selection structure syntax

1. The condition is equivalent judgment, to the point.

2. The default block order can be changed, but pay attention to the execution order. Usually, default is placed at the end or can be omitted.

```switch (expression) {

case Constant 1:

sentence;

break;

case Constant 2:

sentence;

break;

ยทยทยท

default:

sentence;

break;

}

```

Example 6: Zhang San participates in the computer programming competition

If the first place, participate in one month summer camp

If the second place, reward a notebook

If the third place, reward the mobile hard disk

Otherwise, no reward will be given

### last

Many programmers are immersed in the CRUD of business code all day. There is no large amount of data concurrency in the business. They lack practical experience. They only stay in understanding concurrency and can't be proficient. Therefore, they always pass by big manufacturers.

I share the notes and mind map of this set of concurrency system hidden in my pocket. With the combination of theoretical knowledge and project practice, I think you can quickly master concurrent programming as long as you take the time to learn these carefully.

Whether it is to check and fill gaps or in-depth learning, it can have very good results. If you need help, remember to point out praise and support

Java interview selection questions, architecture practice document portal: click here to get it for free

It's not easy to organize. Friends who think it's helpful can help praise, share and support Xiaobian~

Keywords: Java Back-end Interview Programmer

Added by Oaquasis on Tue, 28 Dec 2021 18:14:18 +0200