传智播客C#基础笔记-苏坤(6)

2019-05-17 10:31

{

Console.WriteLine(\请输入工资评定(A-E)\); string imput = Console.ReadLine(); decimal gongzi = 5000m; bool flage = false; switch (imput) {

case \: gongzi += 500; break;

case \: gongzi += 200; break; case \: break;

case \: gongzi -= 200; break;

case \: gongzi -= 500; break;

default: Console.WriteLine(\您输入不在此范围内,请重新输入\); flage = true; break; }

if (flage == false) {

Console.WriteLine(\您的实际工资为:{0}元\, gongzi); Console.ReadKey(); }

If-else if与switch的比较

相同点:都可以实现多分枝结构

不同点:switch:一般只能用于等值比

Console.ReadKey();

If-else if:可以处理范围

三:

Console.WriteLine(\请输入年份\);

int year = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(\请输入月份\);

int mouth = Convert.ToInt32(Console.ReadLine());

if ((year / 400 == 0) || ((year / 4 == 0) && (year / 100 != 0))) {

switch (mouth) {

case 2: Console.WriteLine(\该年该月有29天\); break;

case 4: Console.WriteLine(\该年该月有30天\); break;

case 6: Console.WriteLine(\该年该月有30天\); break;

case 9: Console.WriteLine(\该年该月有30天\); break;

case 11: Console.WriteLine(\该年该月有30天\); break;

default: Console.WriteLine(\改年该月有31\); break;

}

} else {

switch (mouth) {

case 2: Console.WriteLine(\该年该月有28天\); break;

case 4: Console.WriteLine(\该年该月有30天\); break;

case 6: Console.WriteLine(\该年该月有30天\); break;

case 9: Console.WriteLine(\该年该月有30天\); break;

case 11: Console.WriteLine(\该年该月有30天\); break;

default: Console.WriteLine(\改年该月有31\); break; }

Console.ReadKey(); 四:

Console.WriteLine(\请输入你的成绩\);

int input = Convert.ToInt32(Console.ReadLine()); int mod = input/10; switch(mod) {

case 9:Console.WriteLine(\你的综合评定为A\); break;

case 8:Console.WriteLine(\你的综合评定为B\); break;

case 7:Console.WriteLine(\你的综合评定为C\); break;

case 6:Console.WriteLine(\你的综合评定为D\); break;

default:Console.WriteLine(\你的综合评定为E\); break; }

Console.ReadKey();

While 循环的语法: While(条件) //循环体 {

要循环执行的N条程序; //循环体 }

执行过程:

先判断循环条件,如果条件为true,则转向2;如果条件为false,则转向3。

Console.WriteLine(\这道题你会做吗?输入(yes/no)\); string imput = Console.ReadLine(); int i = 0;

if (imput == \) {

while (i < 10) {

Console.WriteLine(\这道题你会做吗?输入(yes/no)\);

imput = Console.ReadLine(); i++; }

}

if (imput == \ || i == 10) {

}

Console.WriteLine(\你可以放学\);

Console.ReadKey();

最后一道:

int year = 2006; double number = 80000; int i = 0;

while(number<200000) {

number = number * (1 + 0.25); i++; }

Console.WriteLine(\到{0}年学员人数将到达20万\,year+i);

Console.ReadKey();

语法: Do

{循环体;} While(条件); 执行过程:

1执行循环体,执行完循环转向2 2判断条件是否成立,如果条件为true,则转向1。如果条件为false,


传智播客C#基础笔记-苏坤(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:古代汉语教案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: