//27,创建一个控制台应用程序,声明两个DateTime类型的变量dt,获取系统的当前日期时间,然后使用Format格式化进行规范
using System;
class Program
{
    static void Main()
    {
        DateTime dt = DateTime.Now;
        string strDate = String.Format("{0:D}", dt);
        Console.WriteLine("今天的日期是:" + strDate);
    }
}
//28,创建一个控制台应用程序,声明一个string类型变量str1,并初始化为“我钟爱C#语言程序设计”,然后用copy方法复制字符串str1,并赋值给字符串str2,最后输出字符串str2
using System;
class Program
{
    static void Main()
    {
        string str1 = "我钟爱C#语言程序设计";
        string str2;
        str2 = string.Copy(str1);
        Console.WriteLine(str2);
    }
}
//29,CopTo方法
using System;
class Program
{
    static void Main()
    {
        string str = "我钟爱C#语言程序设计";
        Console.WriteLine("原字符串:\n" + str);
        char[] myChar = new char[5];
        str.CopyTo(0, myChar, 0, 5);//CopyTo(int需要复制的字符的起始位置,cha[]目标字符数名,指定目标数组中的开始存放位置,int指定要复制的字符个数)
        Console.WriteLine("复制的字符串:");
        Console.WriteLine(myChar);
    }
}

我可以给你们大概算一下有多少个模块 就单纯说些代码的 硬件部门不算
构成设定CLI ,装置维护CLI,环境设定CLI,装置信息查看CLI.快照备份CLI,数据分割CLI,资源分割CLI,性能优化CLI。。。

server, mainserver 设定server,状态监视server,性能监视server,snapshotserver,备份还原server......

还有各种外部tools,还不算OS部门和FW部门

//30,字符串的加密与解密示例
using System;
class Program
{
    static void Main()
    {
        string list = "kczutmhsuasasahsuihsuw";
        char[] str = new char[80];
        int i, j;
        Console.Write("请输入一小写字母串(长度小于80):");
        string c = Console.ReadLine();
        Console.Write("加密后成为:");
        for (i = 0; i < c.Length; i++)
        {
            str[i] = c[i];
            j = str[i] - 97;
            str[i] = list[j];
            Console.Write("{0}", str[i]);
        }
        Console.WriteLine();
    }
}
//31,字符串的解密示例
using System;
class Program
{
    static void Main()
    {
        string list = "qwertyuioplkjhgfdsazxcvbnm";
        char[ ] str = new char[80];
        int i, j;
        Console.Write("请输入需解密的字符串:");
        string c = Console.ReadLine();
        Console.Write("原字符串是:");
        for (i = 0; i < c.Length; i++)
        {
            str[i] = c[i];//
            j = 0;
            while (str[i] != list[j])
                j++;
            str[i] = (char)(j + 97);
                Console.Write("{0}",str[i]);
        }
        Console.WriteLine();
    }
}
//32,有三个字符串,要求找出其中最大者
using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("请先后输入三个字符串,每输入一个请按Enter键确认!");
        string str;
        Console.Write("请输入第1个字符串:");
        string a = Console.ReadLine();
        Console.Write("请输入第2个字符串:");
        string b = Console.ReadLine();
        Console.Write("请输入第3个字符串:");
        string c = Console.ReadLine();
        int m = String.Compare(a, b);
        if (m > 0)
            str = String.Copy(a);
        else
            str = String.Copy(b);
        int n = String.Compare(c, str);
        if (n > 0)
            str = String.Copy(c);
        Console.WriteLine("最大的字符串是:{0}", str);
    }
}
//33,选择排序
using System;
class Program
{
    static void Main()
    {
        string[ ] names = new string[5];
        string max;
        int i, j;
        for(i=0;i<5;i++)
        {
            Console.Write("请输入{0}个国家的名字:",i+1);
            names[i] = Console.ReadLine( );
        }
        for (i = 0; i < names.Length - 1; i++)
        {
            for(j=i+1;j<names.Length;j++)
            {
                int m = String.Compare(names[i], names[j]);
                if (m < 0)
                {
                    max = String.Copy(names[i]);
                    names[i] = String.Copy(names[j]);
                    names[j] = String.Copy(max);
                }
            }
        }
        Console.WriteLine("排序结果:");
        for (i = 0; i < 5; i++)
        {
            Console.Write("{0}  ", names[i]);
        }
        Console.WriteLine();
    }
}
//34.ArrayList数组集合
using System;
using System.Collections;//ArrayList位于Collections中
class Program
{
    static void Main()
    {
        ArrayList myAL = new ArrayList( );
        myAL.Add("Hello");
        myAL.Add("World");
        myAL.Add("!");
        Console.WriteLine("myAL Count:  {0}", myAL.Count);//显示ArrayList的元素个数
        Console.Write("       Value:");
        foreach (Object obj in myAL)
            Console.Write("     {0}", obj);
        Console.WriteLine();
    }
}
//35,输出一个表格的表头,调用方法
using System;
class Program{
    static void printstar()
    {
        Console.WriteLine("*************");
    }
    static void print_message()
    {
        Console.WriteLine("* XSCJFXTJB *");
    }
    static void Main()
    {
        printstar();
        print_message();
        printstar();
    }
}
//36,方法返回值,return语句的一半格式
using System;
class MainClass
{
    static int power(int x, int n)
    {
        int pow = 1;
        while (n > 0)
        {
            n--;
            pow *= x;
        }
        return pow;
    }
    static void Main()
    {
        int n = 3;
        int x = 4;
        char c = 'a';
        Console.WriteLine("power({0},{1},{2})", x, n, power(x, n));
        Console.WriteLine("power('{0}',{1})={2}", c, n, power(c, n));
        Console.WriteLine("power({0},{1}))={2}", n,x, power(n,x));
    }
}
//37,输入两个整数,通过方法的调用输出其中较大的数,求两个整数中的较大数,用方法完成
using System;
class Program
{
    static int max(int x, int y)
    {
        return (x >= y) ? x : y;
    }
    static void Main()
    {
        Console.WriteLine("请输入两个整数:");
        Console.Write("a= ");
        int a = Convert.ToInt32(Console.ReadLine());
        Console.Write("b= ");
        int b=Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("{0:D}和{1:D}较大的数是:{2:D}",a,b,max(a,b));
    }
}
//38,试编程实现方法的嵌套调用
using System;
class Program
{
    static void prnline( )
{
    Console.Write(" - ");
}
    static void print()
    {
        Console.Write(" * ");
        prnline();
        return;
    }
    static void Main()
    {
        int i, j;
        for (i = 0; i < 2; i++)
        {
            for (j = 0; j < 3; j++)
            {
                print();
            }
            Console.WriteLine( );
        }
    }
}
//39,阶乘
using System;
class MainClass
{
    static int fac(int n)
    {
        int y;
        if (n == 1)
            y = 1;
        else
            y = n * fac(n - 1);
        return y;
    }
    static void Main()
    {
        Console.WriteLine("4!={0}",fac(4));
    }
}
//40,n+n^2+n^3+---n^n
//n(1+n(1+n(1+n----)))
using System;
class MainClass
{
    static int fun(int n, int m)
    {
        if (m == 1)
            return n;
        else
            return n * (1 + fun(n, m - 1));
    }
    static void Main()
    {
        Console.WriteLine("n=1:{0}", fun(1, 10));
        Console.WriteLine("n=2:{0}", fun(2, 10));
        Console.WriteLine("n=3:{0}", fun(3, 10));
    }

}
//41,汉诺塔问题
using System;
class Program
{
    static void hanoi(int n, char A, char B, char C)
    {
        if (n == 1)
            Console.WriteLine("将第{0}个盘子从{1}柱搬到{2}柱上;", n, A, C);
        else
        {
            hanoi(n-1,A,C,B);
            Console.WriteLine("将第{0}个盘子从{1}柱搬到{2}柱上",n,A,C);
            hanoi(n-1,B,A,C);
        }
    }
    static void Main()
    {
        char A = 'A', B = 'B', C = 'C';
        Console.WriteLine("请输入A柱上的盘子总数:");
        int n = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("当A柱上有{0}个盘子时,移动步骤依次为:", n);
        hanoi(n, A, B, C);
    }
}
//42,引用参数ref使用示例
using System;
class Program
{
    static void Swap(ref int x, ref int y)
    {
        int temp = x;
        x = y;
        y = temp;
    }
    static void Main()
    {
        int i = 1, j = 2;
        Swap(ref i,ref j);
        Console.WriteLine("i={0},j={1}", i, j);
    }
}
//43,输出参数out使用示例
using System;
class Program
{
    static void Divide(int x, int y, out int result, out int reminder)
    {
        result = x / y;
        reminder = x % y;
    }
    static void Main()
    {
        int res, rem;
        Divide(10, 3, out res, out rem);
        Console.WriteLine("res={0} rem={1}", res, rem);
    }
}
//44.用引用参数ref实现对8名学生各两门成绩的统计,求每门成绩的最低分
using System;
class Program
{
    static void Main()
    {
        int[,] score = { { 98, 82 },{80,76}, { 96, 80 }, { 88, 90 }, { 98, 87 }, { 75, 84 }, { 68, 92 }, { 83, 66 } };
        int min1 = score[0, 0];
        int min2 = score[0, 1];
        minmum(score, ref min1, ref min2);
        Console.WriteLine("课程1最低分:" + min1 + "\n课程2最低分" + min2);
    }
    static void minmum(int[,] score, ref int min1, ref int min2)
    {
        for (int i = 1; i < score.GetLength(0); i++)
            if (score[i, 0] < min1)
                min1 = score[i, 0];
        for (int i = 1; i < score.GetLength(0); i++)
            if (score[i, 1] < min2)
                min2 = score[i,1];
    }
}
//45,用输出参数out实现对8名学生各两门成绩的统计,求每门的最高分
using System;
class Program
{
    static void Main()
    {
        int[ , ]score={{98,82},{80,76},{96,80},{88,90},{98,87},{75,84},{68,92},{83,66}};
        int max1, max2;
        maxmum(score, out max1, out max2);
        Console.WriteLine("课程1最高分:" + max1 + "\n课程2最高分:" + max2);
    }
    static void maxmum(int[,] score, out int max1, out int max2)
    {
        max1 = score[0, 0];
        max2 = score[0, 1];
        for (int i = 1; i < score.GetLength(0); i++)
            if (score[i, 0] > max1)
                max1 = score[i, 0];
        for (int i = 1; i < score.GetLength(0); i++)
        {
            if (score[i, 1] > max2)
                max2 = score[i, 1];
        }
    }
}
//46,定义了3个学生代表,每个学生4次测试成绩对应一个3x4的数组,求所以学生各次考试成绩中的最高成绩
using System;
class Program
{
    static void Main()
    {
        int[,] s = new int[3, 4] { { 68, 77, 73, 86 }, { 87, 96, 78, 89 }, { 90, 70, 81, 86 } };
        Console.WriteLine("最高成绩是:{0}", max(s, 3, 4));
    }
    static int max(int[,] g, int p, int t)
    {
        int m = 0;
        for(int i=0;i<p;i++)
            for(int j=0;j<t;j++)
                if(g[i,j]>m)
                    m=g[i,j];
        return m;
    }
}
//47,输出双精度示例
using System;
class Program
{
    static void Main()
    {
        double a = 123.456789012345;
        Console.WriteLine(a);
        Console.WriteLine("{0:F6}", a);
        Console.WriteLine("{0:F2}", a);
    }
}
//48,设置输出值得货币值与输出宽度示例
using System;
class Program
{
    static void Main()
    {
        int a = 80;
        int b = 8000;
        Console.WriteLine("{0:C2}", a);
        Console.WriteLine("{0:C2}", b);
        Console.WriteLine("{0,5}", a);
        Console.WriteLine("{0,6}", b);
    }
}
//49,利用控制符完成两位小数输出
using System;
class Program
{
    static void Main()
    {
        float x = 168.56f;
        Console.WriteLine("每件平均单价为:{0:F2}", x / 3);
        Console.WriteLine("每件平均单价为:{0:C2}", x / 3);
    }
}
//50,由键盘输入一个华氏温度,将其转化为摄氏温度
using System;
class Program
{
    static void Main()
    {
        Console.Write("请输入华氏温度:");
        String s = Console.ReadLine();
        float f = float.Parse(s);
        float c=(f-32)/1.8f;
        Console.WriteLine("相应的摄氏温度是:{0:F1}", c);
    }
}
//51,由键盘输入三角形的三条边a,b,c,试编程用海伦公式计算任意三角形的面积
using System;
class Program
{
    static void Main()
    {
        double s, area;
        Console.WriteLine("请输入三角形的三条边长:");
        Console.Write("a= ");
        string x = Console.ReadLine();
        Console.Write("b= ");
        string y = Console.ReadLine();
        Console.Write("c= ");
        string z= Console.ReadLine();
        double a = double.Parse(x);
        double b = double.Parse(y);
        double c = double.Parse(z);
        s = 1.0 / 2 * (a + b + c);
        area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
        Console.WriteLine("a={0:F2} b={0:F2} c={0:F2} s={3:F2}", a, b, c, s);
        Console.WriteLine("area={0:F2}", area);
    }
}
//52.设计一个方法,根据三角形的三边长求面积,如果不能构成三角形,给出提示信息
using System;
class Program
{
    static double TriangleArea(float a, float b, float c)
    {
        if ((a + b <= c) || (a + c <= b) || (b + c) <= a)
            return -1;
        double s = (a + b + c) / 2.0;
        return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
    }
    static void Main()
    {
        Console.WriteLine("请输入a,b,c:");
        Console.Write("a= ");
        int a = Convert.ToInt32(Console.ReadLine());
        Console.Write("b= ");
        int b = Convert.ToInt32(Console.ReadLine());
        Console.Write("c= ");
        int c = Convert.ToInt32(Console.ReadLine());
        double area = TriangleArea(a, b, c);
        if(area==-1)
            Console.WriteLine("{0},{1},{2}不能构成三角形!",a,b,c);
        else
        Console.WriteLine("边长为{0},{1},{2}三角形的面积:{3:F1}",a,b,c,area);
    }
}
//53,用方法求两个不等长的数组元素的平均值
using System;
class Program
{
    static void Main()
    {
        double[] a = new double[5] { 2, 3, 6, 8, 10 };
        double[] b = new double[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        double aver1, aver2;
        aver1 = average(a, 5);
        Console.WriteLine("a数组元素的平均值:{0}", aver1);
        aver2 = average(b,10);
        Console.WriteLine("a数组元素的平均值:{0}", aver2);
    }
    static double average(double[] array, int len)
    {
        double sum = 0;
        for (int i = 0; i < len; i++)
        {
            sum += array[i];
        }
        return sum / len;
    }
}

<C#任务导引教程>练习五的更多相关文章

  1. WCF入门教程(五)配置文件

    WCF入门教程(五)配置文件 服务协定以及实现写好后,需要将相关服务公布出去,就需要HOST来承载,供客户端来调用. 承载服务有两种方式,一种通过配置文件,一种通过代码进行配置.上一章已经介绍了代码方 ...

  2. [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)

    [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例) 踏雁寻花 发表于 2015-8-23 23:31:28 https://www.itsk.com/thread-35 ...

  3. Senparc.Weixin.MP SDK 微信公众平台开发教程(五):使用Senparc.Weixin.MP SDK

    Senparc.Weixin.MP SDK已经涵盖了微信6.x的所有公共API. 整个项目的源代码以及已经编译好的程序集可以在这个项目中获取到:https://github.com/JeffreySu ...

  4. Docker入门教程(五)Docker安全

    Docker入门教程(五)Docker安全 [编者的话]DockOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第五篇,介绍了Docker的安全问题,依然是老话重谈,入门者可以通 ...

  5. PyCharm 教程(五)断点 调试

    PyCharm 教程(五)断点 调试 PyCharm 作为IDE,断点调试是必须有的功能.否则,我们还真不如用纯编辑器写的快. [运行]和[调试]前的设置,详见前面的文章,helloword. 1,设 ...

  6. 无废话ExtJs 入门教程十五[员工信息表Demo:AddUser]

    无废话ExtJs 入门教程十五[员工信息表Demo:AddUser] extjs技术交流,欢迎加群(201926085) 前面我们共介绍过10种表单组件,这些组件是我们在开发过程中最经常用到的,所以一 ...

  7. Adafruit的树莓派教程第五课:使用控制电缆

    Adafruit的树莓派教程第五课:使用控制电缆 时间 2014-05-09 01:11:20 极客范 原文 http://www.geekfan.net/9095/ 主题 Raspberry PiM ...

  8. HMM 自学教程(五)前向算法

    本系列文章摘自 52nlp(我爱自然语言处理: http://www.52nlp.cn/),原文链接在 HMM 学习最佳范例,这是针对 国外网站上一个 HMM 教程 的翻译,作者功底很深,翻译得很精彩 ...

  9. Netty4.x中文教程系列(五)编解码器Codec

    Netty4.x中文教程系列(五)编解码器Codec 上一篇文章详细解释了ChannelHandler的相关构架设计,版本和设计逻辑变更等等. 这篇文章主要在于讲述Handler里面的Codec,也就 ...

随机推荐

  1. 测试rac数据文件建本地及处理

    模拟用户zytuser的表空间ZYTUSER_TBS表空间添加数据文件到本地.--环境准备1.创建一个表空间--创建表空间create tablespace ZYTUSER_TBS datafile ...

  2. 深入理解Java虚拟机之JVM内存布局篇

    内存布局**** ​ JVM内存布局规定了Java在运行过程中内存申请.分配.管理的策略,保证了JVM的稳定高效运行.不同的JVM对于内存的划分方式和管理机制存在部分差异.结合JVM虚拟机规范,一起来 ...

  3. S_型文法到q_型文法再到LL(1)型文法演进笔记

    title: S_型文法到q_型文法再到LL(1)型文法演进笔记 date: 2020-08-23 S_型文法到q_型文法再到LL(1)型文法演进笔记 S_型文法(简单的确定性文法) 每个产生式的右部 ...

  4. C#开发BIMFACE系列43 服务端API之图纸拆分

    BIMFACE二次开发系列目录     [已更新最新开发文章,点击查看详细] 在上一篇博客<C#开发BIMFACE系列42 服务端API之图纸对比>的最后留了一个问题,在常规业务场景下,一 ...

  5. C++核心编程 1 程序的内存模型

    1.内存分区模型 C++程序在执行时,将内存大方向划分为4个区域 代码区:存放函数体的二进制代码,由操作系统进行管理(写的所有代码都在代码区) 全局区:存放全局变量.静态变量以及常量 栈   区:由编 ...

  6. Spring 框架学习

    转载自前辈:我没有三个新脏 Spring学习(1)--快速入门 认识 Spring 框架 Spring 框架是 Java 应用最广的框架,它的成功来源于理念,而不是技术本身,它的理念包括 IoC (I ...

  7. Docker 常见命令

    Docker 运行流程 辅助命令 # 1.安装完成辅助命令 docker version -------------------------- 查看docker的信息 docker info ---- ...

  8. 【c++ Prime 学习笔记】第12章 动态内存

    对象的生存期: 全局对象:程序启动时创建,程序结束时销毁 局部static对象:第一次使用前创建,程序结束时销毁 局部自动对象:定义时创建,离开定义所在程序块时销毁 动态对象:生存期由程序控制,在显式 ...

  9. OO_JAVA_四个单元的总结

    总结本单元两次作业的架构设计 设计目标 尽量减少特殊容器的存在,能通用就通用,减少重复的类同代码. 基础容器的存在,就是为上述目标而服务的. 设计概要 底层:基础的.类型无关.无依赖的容器以及对应的查 ...

  10. JVM:垃圾收集器与对象的"存活"问题

    垃圾收集器垃圾收集(Garbage Collection,GC).当需要排查各种内存溢出.内存泄露问题时,当垃圾收集成为系统更高并发量的瓶颈时,我们需要去了解GC和内存分配. 检查对象的"存 ...