-----------------------------------------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;