C#_switch语句,for循环,do while循环,while循环
1:switch语句,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication33
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入分数:");
int score = int.Parse(Console.ReadLine());
Console.WriteLine("得分是:");
switch (score / 10)
{
case 10:
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;
}
}
}
}
运行结果:

2:for循环,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication34
{
class Program
{
static void Main(string[] args)
{
int i;
int sum = 0;
for (i = 0; i <= 100; i++)
{
sum += i;
}
Console.WriteLine("最终结果是:{0}",sum);
}
}
}
运算结果:

3:do while语句,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication35
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int sum = 0;
do
{
sum += i;
i++;
} while (i <= 100);
Console.WriteLine("最终结果是:{0}", sum);
}
}
}
运行结果:

4:while循环,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int sum = 0;
while(i<=100)
{
sum += i;
i++;
}
Console.WriteLine("最终结果是:{0}", sum);
}
}
}
运行结果一样。
5:下面来一个综合的例子,为多名职员计算缴税金额。代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication37
{
class Program
{
static void Main(string[] args)
{
decimal sal;
decimal salary;
decimal tax;
int count = 0;//记录处理数据个数
char ch;//记录用户输入的字符
do
{
Console.Write(++count);
Console.Write("请输入职员工资:");
salary = Convert.ToDecimal(Console.ReadLine());//输入职员工资
sal = salary - 3500;
if (sal <= 0m)
tax = 0m;//decimal类型要加后缀m
else if (sal <= 1500m)
tax = sal * 0.03m;
else if (sal <= 4500m)
tax = sal * 0.1m-105;
else if (sal <= 9000m)
tax = sal * 0.2m-555;
else if (sal <= 35000m)
tax = sal * 0.25m-1005;
else if (sal <= 55000m)
tax = sal * 0.3m-2755;
else if (sal <= 80000m)
tax = sal * 0.35m-5505;
else
tax = sal * 0.45m-13505;
Console.WriteLine("应交税金为:" + tax.ToString());
Console.Write("继续吗?");
ch = Convert.ToChar(Console.ReadLine());//用户输入字符
//若用户输入的是除大小写Y或大小写N以外的其他字符,则要求用户重新输入
while (ch != 'Y' && ch != 'y' && ch !='N' && ch != 'n')
{
Console.WriteLine("对不起!只允许大小写Y或大小写N!\n继续吗?");
ch = Convert.ToChar(Console.ReadLine());
}
}
while (ch == 'Y'||ch == 'y'); Console.WriteLine("谢谢使用!");
Console.ReadLine(); }
}
}
运行结果:

C#_switch语句,for循环,do while循环,while循环的更多相关文章
- 学JAVA第六天,运算符、表达式、if语句以及for、while、都循环
今天老师讲的内容有点多,但是都是在学C#时学过的,用法都差不多,所以很好理解. 算术运算符:+, - ,* , / ,% ,++ ,-- 关系运算符:>,<,>=,<=,== ...
- 自动化运维必须要学的Shell脚本之——循环语句(for、while和until循环)
1. 循环前先了解echo的使用 1.1 echo -n 表示不换行输出 1.2 echo -e 输出转义字符,将转义后的内容输出到屏幕上 常见的转义字符有: 1.2.1 \b 相当于退格键 转义后相 ...
- JS中for循环变量作用域--解决for循环异步执行的问题
被这个问题困惑了很久,终于在网上找到了答案,感谢~ 现在分享给大家~ js中如何让一个for循环走完之后,再去执行下面的语句? 这涉及for循环变量作用域的问题,js中作用域只有函数作用域和全局作用域 ...
- 流程控制,循环结构,for,while循环
'''1.变量名命名规范 -- 1.只能由数字.字母 及 _ 组成 -- 2.不能以数字开头 -- 3.不能与系统关键字重名 -- 4._开头有特殊含义 -- 5.__开头__结尾的变量,魔法变量 - ...
- Shell基础(三):使用for循环结构、使用while循环结构、基于case分支编写脚本、使用Shell函数、中断及退出
一.使用for循环结构 目标: 本案例要求编写一个Shell脚本chkhosts.sh,利用for循环来检测多个主机的存活状态,相关要求及说明如下: 1> 对192.168.4.0/24网段执行 ...
- if continue的用法(跳过本次循环,执行下一个循环)
Python continue 语句跳出本次循环 当需要跳过本次循环的时候,使用continue能跳过本次循环,直接下一个循环 如下脚本: for url in alllink: if url == ...
- Java的三种循环:1、for循环 2、while循环 3、do...while循环
Java的三种循环 Java三种循环结构: 1.for循环 2.while循环 3.do...while循环 循环结构组成部分:1.条件初始化语句,2.条件判断语句 , 3.循环体语句,4.条件控制语 ...
- [Effective JavaScript 笔记]第49条:数组迭代要优先使用for循环而不是for...in循环
示例 下面代码中mean的输出值是多少? var scores=[98,74,85,77,93,100,89]; var total=0; for(var score in scores){ tota ...
- 不可在 for 循环体内修改循环变量,防止 for 循环失去控制
不可在 for 循环体内修改循环变量,防止 for 循环失去控制. #include <iostream> /* run this program using the console pa ...
- python入门:CONTINUE 的作用 跳出本次循环后,重新开始循环
#!/usr/bin/env python # -*- coding:utf-8 -*- # CONTINUE 的作用 跳出本次循环后,重新开始循环 import time while True: ' ...
随机推荐
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
一. 使用证书结合对称加密算法加.解密长数据 上一章节讨论了如何使用RSA证书加密数据,文中提到:“Dotnet的RSA实现有个特点,它必须要在明文中添加一些随机数,所以明文不能把128字节占满,实 ...
- sql server的循环语句
WITH TEST_CTEAS(SELECT id,position,Parentid,Cast(Parentid AS NVARCHAR(4000)) AS PATHFROM op_client_s ...
- 微信公众号支付备忘及填坑之路-java
一.背景 最近公司给第三方开发了一个公众号,其中最重要的功能是支付,由于是第一次开发,遇到的坑特别的多,截止我写博客时,支付已经完成,在这里我把遇到的坑记录一下(不涉及退款).不得不吐槽一下,腾讯这么 ...
- 【php设计模式】建造者模式
<?php /** *建造者模式特点: * 1.客户端不必知道产品内部组成的细节,将产品本身与产品的创建过程解耦,使得相同的创建过程可以创建不同的产品对象. * 2.每一个具体建造者都相对独立, ...
- Spring Cloud(一)服务的注册与发现(Eureka)
Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...
- 【转】在 Delphi 中创建 Linux 守护程序(服务进程)
转自波哥的译文,必须转过来,太有价值了!原文地址在这里.以下为原文内容: 本文译自 原文链接,语言上做了精炼和排版的变更,以便更简洁明了. Delphi 开始支持 Linux 平台为 Delphi 开 ...
- RocketMQ顺序消息
rocketmq的顺序消息需要满足2点: 1.Producer端保证发送消息有序,且发送到同一个队列.2.consumer端保证消费同一个队列. 生产端: RocketMQ可以严格的保证消息有序.但这 ...
- 图像处理---《Mat对象 与 IplImage对象》
图像处理---<认识 Mat对象> Mat对象 与 IplImage对象 (1)Mat对象:OpenCV2.0之后引进的图像数据结构.自动分配内存.不存在内存泄漏的问题,是面向对象的数据结 ...
- windows下通过批处理脚本启动redis
三种启动方式的特点: 第一种方式 :根目录之命令窗口启动 特点:每次启动都要进入到redis的根目录,比较繁琐,并且占用一个窗口 第二种方式:bat脚本便捷启动 特点:可放在桌面便捷启动,占用窗口 第 ...
- withdraw搭建
<!-- yuan -->首先得安装rabbitmq(由于运行过程中报错)1.安装rabbitmq服务软件包 : apt install rabbitmq-server2.安装完成后在ra ...