• ===习题


    第一章1.
    int
    n, i; int result = 0; Console.WriteLine("请输入一个正整数"); n = int.Parse(Console.ReadLine()); if (n % 2 == 1)//判断n是否为奇数 { for (i = 1; i<=n;) { result = result + i; i = i + 2; } } else { for (i = 0; n>i;) { i = i + 2; result = result + i; } } Console.WriteLine(result); Console.Read(); }
    11.
     int i;
                string s_text, s_key, s_result=null;
                char ch;
                Console.WriteLine("请输入原字符串:");
                s_text = Console.ReadLine();
                Console.WriteLine("请输入密钥字符串:");
                s_key = Console.ReadLine();
                if (s_text.Length != s_key.Length)
                {
                    Console.WriteLine("密钥字符串与原字符串长度必须相等");
                    return ;
                }
                    for(i=0;i<s_text.Length-1;i++)
                    {
                        ch =Convert.ToChar(s_text[i]^s_key[i]);
                        s_result+=ch;
                    }
                
                Console.WriteLine("加密后的字符串为:");
                Console.WriteLine(s_result);
                Console.ReadKey();
    
    
    
     

     第二章1

    namespace Test2_1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Animal ani = new Animal();
                Console.WriteLine(ani.Introduce());
                Dog dog = new Dog();
                Console.WriteLine(dog.Introduce());
                Cat cat = new Cat();
                Console.WriteLine(cat.Introduce());
                Console.ReadKey();
            }
        }
    }
     
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Test2_1
    {
        class Animal
        {
            bool m_sex;
            int m_age;
            public Animal()
            {
                Sex = false;
            }
            public bool Sex
            {
                get { return m_sex; }
                set { m_sex = value; }
            }
            public int Age
            {
                get { return m_age; }
                set { m_age = value; }
            }
            public virtual string Introduce()
            {
                if (Sex)
                    return "This is a male Animal!";
                else
                    return "This is a female Animal!";
            }
        }
        class Dog:Animal
        {
           public Dog()
            {
                Sex = true;
            }
     
            public override string Introduce()
            {
                if (Sex)
                    return "This is a male Dog!";
                else
                    return "This is a female Dog!";
            }
        }
        class Cat : Animal
        {
            public Cat()
            {
                Sex = false;
            }
            public override string Introduce()
            {
                if (Sex)
                    return "This is a male Cat!";
                else
                    return "This is a female Cat!";
            }
        }
    }
  • 相关阅读:
    Java实现 LeetCode 167 两数之和 II
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 1227 飞机座位分配概率
    Java实现 LeetCode 166 分数到小数
    QueryPerformanceFrequency 和 QueryPerformanceCounter用法
    VC中利用多线程技术实现线程之间的通信
    C++著名类库和C++标准库介绍
    CRectTracker类的使用--橡皮筋窗口
    备份3个判断指针是否有效的函数,以备不时之需
  • 原文地址:https://www.cnblogs.com/7-58843117/p/7523753.html
Copyright © 2020-2023  润新知