Hello, everyone. It's time to summarize the knowledge. Today, I learned a circular statement from cloud and college. Below are some of my general knowledge points.
Add the switch statement in the Selected structure.
Theory: The switch statement is a multi-branch selection statement. You can use the switch statement to test a large number of selection items. The switch structure can be used to replace multiple select path if statements.
Format: switch (expression)
{
Case constant expression 1:
Statement 1;
Break;
Case constant expression 2:
Statement 2;
Break;
.
.
Case constant expression n:
Statement n;
Break;
Default;
Statement n + 1;
Break;
}
Note: the expression type can be integer or string, and the constant expression type after each case must be the same as the expression type or be implicitly converted to the expression type. The constant expressions after each case cannot be equal. Each case branch must end with a break statement, return statement, goto statement, or throw statement; in addition, no code in the statement can modify the value of the expression after the switch.
Loop statement -- while
While (expression)
{
Statement;
}
Practical questions:
In the year-end work evaluation of Li Si, if it is set to a, the salary will increase by 500 yuan. If it is set to B, the salary will increase by 200 yuan. If it is set to C, the salary will remain unchanged, if the D-level salary is set to drop 200 yuan, if the e-level salary is set to drop 500 yuan. set the original salary of Li Si to 5000. Ask the user to enter the grade of Li Si, and then display the salary of Li Si for the next year.
Console. writeLine ("Enter Li Si's rating"); string dengji = Console. readLine (); decimal money = 5000; decimal moneys = 0; switch (dengji) {case "A": moneys = money + 500; break; case "B ": moneys = money + 200; break; case "C": moneys = money; break; case "D": moneys = money-200; break; case "E ": moneys = money-500; break;} Console. writeLine ("Li Si's salary for the next year: {0}", moneys); Console. readKey ();
Li Si was careless in this exam. His father asked him to write 1000 times "be careful in the next exam ".
Int I = 0; while (I <= 1000) {I ++; Console. WriteLine ("Be careful next time");} Console. ReadKey ();
Enter the year, the month, and the number of days of the month.
Console. writeLine ("Enter the year"); string year = Console. readLine (); int years = Convert. toInt32 (year); Console. writeLine ("Enter the month"); string month = Console. readLine (); int month1 = Convert. toInt32 (month); if (month = "2") {if (years % 400 = 0 | years % 4 = 0 & years % 100 = 0) {Console. writeLine ("29 days this month");} else {Console. writeLine ("28 days this month") ;}} else if (month1 >=1 & month1 <= 12 & month1! = 2) {switch (month) {case "1": case "3": case "5": case "7": case "8": case "10 ": case "12": Console. writeLine ("31 days in this month"); break; default: Console. writeLine ("30 days this month"); break ;}} else {Console. writeLine ("input error, please enter again");} Console. readKey ();
• The teacher asked the students, will you do this? If the student answers "Yes (y)", the student can leave school. if the student does not do (n), the teacher will repeat it again and ask if the student will do it ......
-School is not available until the student union ends.
-It will not happen until the student union or the teacher tells him 10 times. School is required.
Int a = 1; Console. WriteLine ("the instructor asked students, will you do this? Y/n "); string stu1 = Console. readLine (); if (stu1 = "n") {do {a ++; Console. writeLine ("the teacher asked the students, will you do this? Y/n ");} while (a <= 10); Console. writeLine ("School");} else {Console. writeLine ("School available");} Console. readKey ();
When I enter "n", the running result is:
I didn't give the correct answer to this question. I don't know where the program has a problem. Please advise.
Enze fourth day (loop statement 1)