##Topic 1 (training)
Let the user enter three integers in turn, calculate the minimum value of the three numbers, and print it to the console.
###Training tips
1. How to complete user entry?
2. What knowledge points are needed to find the minimum value?
###Problem solving scheme
1. Use Scanner to complete keyboard entry, and use if Nested complete judgment of else
2. Use Scanner to complete keyboard entry, and use multi conditional if Else complete judgment
The following solutions are subject to scheme 2
###Operation steps
1. Use the method of three keyboard entries to allow the user to enter three integers
2. Use multi conditional if Else judges various situations of the size relationship of the three numbers and obtains the minimum value
3. Print out minimum value
###Reference answer
```java //1. Guide Package import java.util.Scanner; public class Demo2 { public static void main(String[] args) { //2. Create a keyboard entry object Scanner sc = new Scanner(System.in); //3. Enter three numbers respectively System.out.println("Please enter the first integer:"); int i = sc.nextInt(); System.out.println("Please enter the second integer:"); int j = sc.nextInt(); System.out.println("Please enter the third integer:"); int k = sc.nextInt(); //4. Define variables to represent the minimum value int min; //5. Judge three integers if( i < j && i < k){ min = i; }else if( j < i && j < k){ min = j; }else{ min = k; } //6. Print minimum value System.out.println("The minimum value is" + min); } }
##Topic 2 (comprehensive)
A shopping mall can offer discounts. The specific rules are as follows:
Ordinary customers do not discount if they buy less than 100 yuan, and 10% off if they buy more than 100 yuan;
20% off for members who buy less than 200 yuan and 7.5% off for members who buy more than 200 yuan;
Different discount rules are not cumulative.
Please make shopping settlement according to this preferential plan, enter the customer category (0 for ordinary customers, 1 for members) and the pre discount amount of shopping (integer), and output the payable amount (decimal type).
###Training tips
1. What methods are used to allow users to enter content?
2. Which if statement format is used to judge the information?
###Problem solving scheme
1. Use the Scanner keyboard to enter and if The nesting of else judgment statements is completed by using.
###Operation steps
1. Enter the member category and shopping amount with the keyboard.
2. First use if else to judge the customer category.
3. Use the if else statement to judge the shopping amount in different customer categories.
4. Output results.
###Reference answer
```java //1. Guide Package import java.util.Scanner; public class Demo4 { public static void main(String[] args) { // 2. Create a keyboard entry object Scanner sc = new Scanner(System.in); // 3. Call the method to obtain the customer category and shopping amount entered by the keyboard System.out.println("Please enter the customer category (0 for ordinary customers and 1 for member customers):"); int type = sc.nextInt(); System.out.println("Please enter the purchase amount:"); int money = sc.nextInt(); // 4. Judge the customer category first if (type == 0) { // 4.1. Ordinary customers, and then judge the shopping amount if (money > 0 && money < 100) { System.out.println("Your payable amount is:" + money); } else if (money >= 100) { System.out.println("Your payable amount is:" + money * 0.9); } else { System.out.println("The amount you entered is incorrect"); } } else if (type == 1) { // 4.2. Member customers, and then judge the shopping amount if (money > 0 && money < 200) { System.out.println("Your payable amount is:" + money * 0.8); } else if (money >= 200) { System.out.println("Your payable amount is:" + money * 0.75); } else { System.out.println("The amount you entered is incorrect"); } } else { System.out.println("The customer category you entered is incorrect"); } } }
##Topic 3 (comprehensive expansion)
From January 1, 2019, the state will launch a new individual income tax policy, with a value adjustment of 5000 yuan on the threshold. In other words, if the pre tax salary is less than 5000 yuan after deducting three insurances and one fund (the amount of three insurances and one fund is assumed to be 10% of the pre tax salary), no tax will be paid. If it is greater than 5000 yuan, the part greater than 5000 yuan shall be taxed according to the gradient. The specific gradient proportion is as follows:
3% for the part of 0 ~ 3000 yuan
10% for the part of 3000 ~ 12000 yuan
12000 ~ 25000, 20% tax
25% for 25000 ~ 35000
For 35000 ~ 55000, 30% tax shall be paid
35% for 55000 ~ 80000
For the part exceeding 80000, 45% tax shall be paid
For example, after a student from dark horse joins an enterprise, his pre tax salary is 15000, then the part he should pay personal tax every month is 15000-1500-5000 = 8500 yuan, and the amount of personal tax paid is 3000 yuan × 3%+5500 × 10% = 640 yuan. The after tax salary is 12860 yuan.
Please complete a personal income tax calculation program. After the user enters the pre tax salary, calculate the corresponding tax amount and the post tax salary?
###Training tips
1. Which parts of wages are taxable and how to calculate them?
2. The tax proportion has many intervals. What knowledge points can correspond to multiple intervals?
3. What is the tax amount of each interval and what is the calculation law?
###Problem solving scheme
1. Use multi conditional if Else calculates the tax amount of each tax gradient corresponding to each tax gradient.
###Operation steps
1. Prompt the user to enter the pre tax salary, and use the keyboard to enter an integer.
2. Calculate the taxable part of salary. That is to remove the amount of three insurances and one gold and the threshold.
3. Use multi conditional if else.. Judge each interval separately, and calculate the corresponding tax amount with the calculation formula of each gradient.
4. Calculate the after tax salary according to the calculated tax amount.
###Reference answer
```java //1. Guide Package import java.util.Scanner; public class Demo5 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter your pre tax salary:"); //2. Enter pre tax salary with keyboard int money = sc.nextInt(); //3. Calculate the salary of the taxable part double before = money - (money*0.1) - 5000; //4. Define individual income tax variables double shui = 0; //5. Calculate the individual income tax value according to the gradient range if(before > 0 && before <=3000){ shui = before * 0.03; }else if(before > 3000 && before <=12000){ shui = 3000*0.03 + (before-3000) * 0.1; }else if(before > 12000 && before <=25000){ shui = 3000*0.03 + 9000*0.1 + (before-12000)*0.2; }else if(before > 25000 && before <=35000){ shui = 3000*0.03 + 9000*0.1 + 13000*0.2 + (before-25000)*0.25; }else if(before > 35000 && before <=55000){ shui = 3000*0.03 + 9000*0.1 + 13000*0.2 + 10000*0.25 + (before-35000)*0.3; }else if(before > 55000 && before <=80000){ shui = 3000*0.03 + 9000*0.1 + 13000*0.2 + 10000*0.25 + 20000*0.3 + (before-55000)*0.35; }else if(before > 80000){ shui = 3000*0.03 + 9000*0.1 + 13000*0.2 + 10000*0.25 + 20000*0.3 + 25000*0.35 + (before-80000)*0.45; } //6. Calculate after tax salary double after = money - (money*0.1) - shui; //7. Print individual income tax and after tax salary System.out.println("individual income tax" + shui + "element"); System.out.println("After tax salary" + after + "element"); } }
#Knowledge points
switch judgment statement
##Topic 1 (comprehensive)
Analog calculator function, add, subtract, multiply and divide the two int type data entered by the keyboard, and print the operation results.
requirement:
Enter three integers on the keyboard. The first two integers represent the data participating in the operation, and the third integer is the operation to be performed (1: addition operation, 2: subtraction operation, 3: multiplication operation, 4: division operation). The demonstration effect is as follows:
Please enter the first integer: 30
Please enter the second integer: 40
Please enter the operation you want to perform (1: for addition, 2: for subtraction, 3: for multiplication, 4: for division): 1
Console output: 30 + 40 = 70
###Training tips
1. After the user enters the data, what knowledge points are used to judge the four different operations of addition, subtraction, multiplication and division?
###Problem solving scheme
1. Use switch to judge whether the statement is complete.
###Operation steps
1. Use the keyboard to enter three variables.
2. Use the switch judgment statement to judge the third variable and match the operation to be executed.
3. Perform different operations on the first variable and the second variable in each case.
###Reference answer
```java // 1. Guide Package import java.util.Scanner; public class Demo2 { public static void main(String[] args) { // 2. Create a keyboard entry object Scanner sc = new Scanner(System.in); // 3. Prompt the data to be input and call the method to obtain the input data System.out.println("Please enter the first integer:"); int num1 = sc.nextInt(); System.out.println("Please enter the second integer:"); int num2 = sc.nextInt(); System.out.println("Please enter the operation you want to perform(1:Represents addition,2:Representation subtraction,3:Represents multiplication,4:Representation Division)"); int type = sc.nextInt(); // 4. Use the switch statement to judge the calculation type and output the corresponding results switch (type) { case 1: System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); break; case 2: System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); break; case 3: System.out.println(num1 + " * " + num2 + " = " + (num1 * num2)); break; case 4: System.out.println(num1 + " / " + num2 + " = " + (num1 * 1.0 / num2)); break; default: System.out.println("The operation category you entered is incorrect"); break; } } } ```
#####See the results of compiling and running the following code: ()
public static void main(String[] args) {
int pigs = 5;
boolean isOne = true;
boolean isTwo = false;
if ((pigs == 4) && !isTwo){
System.out.print("first");
System.out.print("second ");
}
if ((isTwo == false) && isOne) {
System.out.print("third");
}
}
A. Compilation error: B. output: third C. output: first second D. output: second third
#####The output of the following program is: ()
public static void main(String[] args) {
int a = 1;
int b = 2;
if(a == 1){
System.out.println("hello1");
}else if(b == 2){
System.out.println("hello2");
}else{
System.out.println("hello3");
}
}
A.hello1
B. hello2
C.hello3
D.hello1hello2
#####Which of the following parameters cannot be used in a switch statement?
a. byte b=1;
b. int i= 1;
c.boolean b=false;
d.char c='a';
#####Which of the following if statements is correct?
if(x++){
y=x*Z;
x/=2;
else{
y=y*y;
++ Z;
}
a. if condition cannot use post operator;
b. The if condition must be Boolean and cannot be numeric;
c.else must be followed by if();
d. This is a multi branch if statement
#####The output of the following code is ()
int year = 2046;
if(!year % 2 == 0){
System.out.println("entered if");
}else{
System.out.println("entered else");
}
System.out.println("exit");
A. Entered if
B. Entered else
C. Quit
D. Enter else, exit
In Java, the output of the following code is ()
**int** i=1;
**switch**(++i){
**case**1:
System.**out**.println("i is 1");
**case**2:
System.**out**.println("i is 2");
**case**3:
System.**out**.println("i is 3");
**default**:
System.**out**.println("i does not meet the judgment conditions");
}
A. i is 2
B. i is , i is 2 , i is 3 , i does not meet the judgment conditions
C. i is 2 ^ i does not meet the judgment conditions
D. i is 2 , i is 3 , i does not meet the judgment conditions