C#_switch语句,for循环,do while循环,while循环

摘要:
代码如下:usingSystem;使用System.Collections.Generic;使用System.Linq;使用System.Text;使用System.Threading.Tasks;NamespaceConsoleApplication37{classProgram{staticvoidMain{decimalsal;decimalsalary;decimalaltax;intcount=0;//记录数据处理的字符数;//记录用户输入的字符{Console.Write;Console.Writer;salary=Convert.ToDecimal;//输入员工工资sal=salary-3500;iftax=0m;//十进制类型应加上melseiftax=sal*0.03m;elseiftax=sal*0.1m-105;elseivitax=sal*0.2m-555;elsieftax=sal*0.2m-1005;elseeftax=萨尔*0.3m-2755;elseivtax=sal*0.35m-555;elseidtax=sal+0.45m-1350 5;Console.WriteLine;Console.Write(“是否继续?”);ch=转换为字符;//用户输入字符//如果用户输入的字符不是大小写Y或N,则需要用户在(ch!“);Console.ReadLine();}}运行结果时重新输入:

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;
            }
        }
    }
}

 运行结果:

C#_switch语句,for循环,do while循环,while循环第1张

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);
        }
    }
}

 运算结果:

C#_switch语句,for循环,do while循环,while循环第2张

 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);
        }
    }
}

  运行结果:

C#_switch语句,for循环,do while循环,while循环第3张

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!
继续吗?");
                    ch = Convert.ToChar(Console.ReadLine());
                }
            }
            while (ch == 'Y'||ch == 'y');

            Console.WriteLine("谢谢使用!");
            Console.ReadLine();

        }
    }
}

  运行结果:

C#_switch语句,for循环,do while循环,while循环第4张

免责声明:文章转载自《C#_switch语句,for循环,do while循环,while循环》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【网络流#5】UVA 11082 最大流取前十条取后十条取区间值-限制取数区间下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C#开发规范总结(个人建议)

.NET开发编程规范 第1章程序的版式 版式虽然不会影响程序的功能,但会影响可读性。程序的版式追求清晰、美观,是程序风格的重要构成因素。 可以把程序的版式比喻为"书法"。好的"书法"可让人对程序一目了然,看得兴致勃勃。差的程序"书法"如螃蟹爬行,让人看得索然无味,更令维护者烦恼有加。 1.1 版本和版权声明 版本和版权的声明写在文件的开头,包含内容如下:...

Oracle学习(11):PLSQL程序设计

PL/SQL程序结构及组成 什么是PL/SQL? •PL/SQL(Procedure Language/SQL) •PLSQL是Oracle对sql语言的过程化扩展 •指在SQL命令语言中添加了过程处理语句(如分支、循环等),使SQL语言具有过程处理能力。 SQL长处 交互式非过程化。 数据操纵功能强; 自己主动导航语句简单; 调试ea...

Oracle- 表查询

这些都比较基础,还是重温一下。 一、简单的查询语句1、查询表结构sql>desc dept; (使用PL/SQL Developer查询时,必需在命令窗口才能使用该语句) 2、查询所有列sql>select * from dept; 3、查询指定列sql>select ename,sal,job,deptno from emp; 4、如何...

lua for循环

《转自网络,仅供学习》 for循环是一个循环控制结构,可以有效地编写需要执行的特定次数的循环。 语法 Lua编程语言的for循环的语法是: for init,max/min value, increment do statement(s) end 下面是控制在一个循环的流程: 初始化步骤首先被执行,并且仅一次。这个步骤可让您声明和初始化任何循环控制...

oracle教程:PLSQL常用方法汇总

oracle教程:PLSQL常用方法汇总 在SQLPLUS下,实现中-英字符集转换alter session set nls_language='AMERICAN';alter session set nls_language='SIMPLIFIED CHINESE';主要知识点:一、有关表的操作1)建表 create table test as sel...

Oracle游标(光标)

# 游标(光标)cursor:集合 语法:    declare     cursor 光标名(参数列表)   is # 光标的属性   %isopen    %rowcount    %found   %notfound --查询并打印全部员工的姓名、薪水 SET SERVEROUTPUT ON declare cursor cemp is...