if -else / switch-case 练习试手
1.(查看代码点击View Code左侧 + )
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 String s1=console.ReadLine(); 2 Int user = convert.Toint32(s1); 3 If(user==88888888) 4 { 5 Console.writeline(“密码正确”); 6 } 7 Else 8 { 9 Console.writeline(“密码错误”); 10 } 11 Console.ReadKey();
2.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 Console.WriteLine("请输入密码"); 2 string s1 = Console.ReadLine(); 3 if (s1 == "888888") 4 { 5 Console.WriteLine("密码正确"); 6 } 7 else 8 { 9 Console.WriteLine("密码错误,再输入一次"); 10 s1 = Console.ReadLine(); 11 if (s1 == "888888") 12 { 13 Console.WriteLine("密码正确"); 14 } 15 else 16 { 17 Console.WriteLine("密码错误"); 18 } 19 } 20 Console.ReadKey(); 21 {
3.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 console.writeline("你现在看的可能是爱情动作片,请输入你的年龄?"); 2 int age=convert.toint32(console.readline()); 3 if (age>=18) 4 { 5 console.writeline("允许观看"); 6 } 7 else if (age >=10) 8 { 9 console.writeline("你确定要观看?(输入yes观看,其他退出)") 10 string input = console.readyline(); 11 if (input=="yes") 12 { 13 console.writeline("请观看!"); 14 } 15 else 16 { 17 console.writeline("你放弃了观看!"); 18 } 19 } 20 else 21 { 22 console.writeline("年龄太小,禁止观看!"); 23 }