黑马程序员之基础题学习笔记:基础测试

-----------------------------------------2345王牌技术员联盟2345王牌技术员联盟、期待与您交流!---------------------------------------------

1、编写程序计算1+2+3+....+100的和。

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

 

namespace TEST_1

{

    class Sum

    {

        static void Main(string[]args)

        {

                int i;

                int sum = 0;

                for (i = 0; i < =100; i++)

                {

                     sum=sum+ i;

                }

                Console.WriteLine("计算后的和为:{0}",sum);

                Console.ReadKey();

        }

    }

}

 


2、已知一个int数组,编程从数组中获取最大数。

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

 

namespace TEST_2

{

    class Max

    {

              static int MaxValue(int[] intArray)

             {

                        int maxVal = intArray[0];

                        for(int i = 0; i < intArray.Length - 1; i++)

                       {

                                if (intArray[i] > maxVal)

                                maxVal = intArray[i];

                       }

                             return maxVal;

              }

             static void Main(string[]args)

             {

                      int[] myArray = {123, 22, 33, 8, 66, 55, 99,3, 2, 1 };

                      int maxVal = MaxValue(myArray);

                      Console.WriteLine("最大数为:{0}", maxVal);

                      Console.ReadKey();                        

             }

     }

}

 

3、用户输入一个“2008-01-02”格式的日期,分析用户输入的日期然后按照“2008年1月2日”的格式重新输出。

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

 

namespace TEST_3

{

    class Max

    {

           static void Main(string[]args)

           {

                     Console.WriteLine();
                     Console.WriteLine("请输入要转换的日期:");   
                   
 string date = Console.ReadLine();                  

                     string[] t = date.Split('-');

                     Console.WriteLine("{0}"+ "" + "{1}" +""+"{2}"+"", t[0],t[1],t[2]);

                     Console.ReadKey();

           }

    }

}

 

4、编写一个类Person,为Person类定义年龄、姓名两个属性,并且定义一个SayHello方法,方法执行时输出“我是***我的年龄是***”;定义一个Chinese类从Person类继承。

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值