using System; /*2018-12-27 c#学习笔记 * 1.c#判断if /else if /switch * 2.循环while/for/do-while * 3.循环实例: for循环99乘法表 /while 循环99乘法表/do while 循环99乘法表 */ namespace Csharp_study { class section2 { static void Main(string[] args) { //1.c#判断if /else if /switch double score = 67; double score2= 91; if (score > 60) { Console.WriteLine("及格"); } else { Console.WriteLine("不及格"); } //else if if (score2<60) { Console.WriteLine("不及格"); } else if (score2>90) { Console.WriteLine("优秀"); } else { Console.WriteLine("一般"); } //switch string score3 = "A"; switch (score3){ case "A": Console.WriteLine("优秀!"); break; case "B": Console.WriteLine("一般"); break; case "D": Console.WriteLine("不合格"); break; default: Console.WriteLine("合格"); break; } //三目运算符?: 等同于if else string jieguo = (score < 60) ? "及格" : "不及格"; Console.WriteLine(jieguo); //2.循环 //while int i = 10; while (i > 0) { Console.WriteLine(i); i--; } //do while int j = 0; do { j++; Console.WriteLine(j); }while (j<10); //for循环 Console.WriteLine("20以内3的倍数:"); for (int z = 1; z < 20; z++) { if (z % 3 == 0) { Console.WriteLine(z); } } //3.循环实例: for循环99乘法表 /while 循环99乘法表/do while 循环99乘法表 //for循环 for (int x = 1; x <=9;x++ ) { for (int z = 1; z<=x; z++) { Console.Write("{0}*{1}={2} ",z,x,x*z); } Console.Write(" "); } //while 循环 Console.Write("----------------------------------------------------------------- "); int x2 = 1; while (x2<=9) {//外层循环 int y2=1; while (y2 <= x2) {//内层循环 Console.Write("{0}*{1}={2} ", y2, x2, x2 * y2); y2++; } Console.Write(" "); x2++; } //do while 循环 Console.Write("----------------------------------------------------------------- "); int aa = 1; do{//外层循环 int bb=1; do{//内层循环 Console.Write("{0}*{1}={2} ", aa, bb, aa * bb); bb++; }while(bb<=aa); aa++; Console.Write(" "); } while (aa <=9); Console.ReadKey(); } } }