A.1.4,6,7-控制结构(if else),循环结构(for,while,do while),循环结构(switch)

ylbtech- .NET-Basic: A.1.4,6,7-控制结构(if_else),循环结构(for,while,do while),循环结构(switch)

 A.1.4-控制结构(if else) ==1.A

 A.1.6-循环结构(for,while,do while) ==1.A.2

 A.1.7-循环结构(switch) ==1.A.3

1.A,源代码返回顶部
using System;

namespace Test4
{
    class Program
    {
        static void Main(string[] args)
        {
            //选择结构
            //if(t条件)
            //{
            //}
            Console.WriteLine("请输入您的年龄?");
            int age = int.Parse(Console.ReadLine());
            if (age > 18)
            {
                Console.WriteLine("成年人");
            }
            else
            {
                Console.WriteLine("未成年人");
            }

            Console.ReadLine();
        }
    }
}
1.A.2,源代码返回顶部
using System;

namespace test7
{
    class Program
    {
        static void Main(string[] args)
        {

            //循环结构
            //1,for
            Console.WriteLine("1,***************************************");
            for (int i = 1; i <= 9; i++)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("2,***************************************");
            //2,while
            //当条件满足实执行
            int num = 8;
            while (num > 0)
            {
                Console.WriteLine(num);
                num--;
            }
            Console.WriteLine("3,***************************************");
            //3,do while
            //先执行一次,然后在判断条件是否满足
            int num2 = 7;
            do
            {
                Console.WriteLine(num2);

            } while (num2<7);
        }
    }
}
1.A.3,源代码返回顶部
using System;

namespace tests6
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("请输入当前礼拜几的代码?");
            int day =Convert.ToInt32(  Console.ReadLine());
            switch (day)
            {
                case 6:
                    Console.WriteLine("休息日");
                    break;
                case 0:
                    Console.WriteLine("休息日");
                    break;
                default:
                    Console.WriteLine("工作日");
                    break;
            }

            Console.ReadLine();
        }
    }
}
warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted on 2013-03-25 09:45  ylbtech  阅读(254)  评论(0编辑  收藏  举报