课堂练习:1.一个四位整数 输出它的千位,百位,十位,个位 数字。 int a = 1894; int b = a / 1000; int c = a / 100 % 10; int d = a / 10 % 10; int e = a % 10; Console.WriteLine("千位数" + b+" 百位数"+c +" 十位数"+d+" 个位数"+e); 课堂练习: 2.机票预定:输出实际机票价格原价为4000元5-10月为旺季,头等舱打9折,经济舱打7.5折其他时间为淡季,头等舱打6折,经济舱打3折 int month=11; int type = 1; double money = 4000; if(month>=5 && month<=10){ if (type == 1) { Console.WriteLine("您的机票价格为:{0}", money * 0.9);} else if (type == 2){ Console.WriteLine("您的机票价格为:{0}", money * 7.5);}} else{ if (type == 1){ Console.WriteLine("您的机票价格为:{0}", money * 0.6);} else if (type == 2){ Console.WriteLine("您的机票价格为:{0}", money * 0.3);} } 课堂练习:3.输入学员的名字输出 该学员的 姓名,专业,分数。 string name1 = "张三", subject1 = "c#", score1 = "90"; string name2 = "李四", subject2 = "asp.net", score2 = "95"; Console.WriteLine("请输入学员的名称"); string name = Console.ReadLine(); switch (name) { case "张三": Console.WriteLine("{0}\t{1}\t{2}", name1, subject1, score1); break; case "李四": Console.WriteLine("{0}\t{1}\t{2}", name2, subject2, score2); break; default: Console.WriteLine("抱歉!没有你要找的学员!"); 课堂练习:4.从控制台输入数字 如果为幸运数字 提示:"中奖了 奖励。。。";如果不是幸运数字 提示 :"请 在接在励";随机数范围 1~~10; Random number = new Random(); int A = number.Next(1, 10); Console.WriteLine("请输入数字"); string BB = Console.ReadLine(); int bb = int.Parse(BB); int cc = bb == A ? 1 : 0; //判断是否正确 switch (cc) { case 1: Console.WriteLine("中奖了 奖励。。。"); break; default: Console.WriteLine("请在接在励"); break; } Console.ReadKey();
本系列教程:
http://www.cnblogs.com/spring_wang/p/6113526.html
http://www.cnblogs.com/spring_wang/p/6113496.html
http://www.cnblogs.com/spring_wang/p/6113404.html
http://www.cnblogs.com/spring_wang/p/6113383.html
http://www.cnblogs.com/spring_wang/p/6113285.html
http://www.cnblogs.com/spring_wang/p/6113274.html
http://www.cnblogs.com/spring_wang/p/6113258.html
http://www.cnblogs.com/spring_wang/p/6113232.html
http://www.cnblogs.com/spring_wang/p/6113224.html
http://www.cnblogs.com/spring_wang/p/6112885.html