首页 > 其他 > 详细

===习题

时间:2017-09-17 23:55:07      阅读:425      评论:0      收藏:0      [点我收藏+]
第一章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!";
        }
    }
}

 

===习题

原文:http://www.cnblogs.com/7-58843117/p/7523753.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!