zoukankan      html  css  js  c++  java
  • <C#任务导引教程>练习四

    //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("原字符串: " + 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,方法返回值
    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("pow({0},{1})=){2}", x, n, power(x, n));
            Console.WriteLine("pow('{0}',{1})=){2}", c, n, power(c, n));//注意char字符的输出格式
            Console.WriteLine("pow({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,求4!
    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));
        }
    }

  • 相关阅读:
    鸟哥的linux私房菜
    jquery mobile 移动web(2)
    jquery mobile 移动web(1)
    HTML5规范的本地存储
    初探css3
    移动设备HTML5页面布局
    jquery 操作ajax 相关方法
    jQuery 效果使用
    jquery 表单事件
    jquery鼠标事件
  • 原文地址:https://www.cnblogs.com/zhangyongjian/p/3621629.html
Copyright © 2011-2022 走看看