基础测试

 

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

                            int i;

                            int sum = 0;

                            for (i = 0; i < 101; i++) {

                                     sum += i;

                                     }

                            Console.WriteLine("{0}",sum);

                            Console.ReadKey();

 

 

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

                   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 = {129, 8, 3, 6, 2, 5, 9, 3, 0, 2 };

                            int maxVal = MaxValue(myArray);

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

         Console.ReadKey();         

                   }

 

 

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

                   static void Main(string[] args) {

                            string time = "2008-1-2";                    

                            string[] a = time.Split('-');

                            Console.WriteLine("{0}" + "年" + "{1}" + "月"+"{2}"+"日", a[0],a[1],a[2]);

                            Console.ReadKey();

                   }

 

 

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

         class Program {

 

                   static void Main(string[] args) {

                            Chinese c = new Chinese();

                            c.Age = 24;

                            c.Name = "smile";

                            c.SayHello();

                   }

         }

         abstract class Person {

                   private string name;

                   private int age;

                   public int Age {

                            get { return age; }

                            set { age = value; }

                   }

                   public string Name {

                            get { return name; }

                            set { name = value; }

                   }

                   public abstract void SayHello();

         }

         class Chinese:Person

         {

                   public override void  SayHello(){

                            Console.WriteLine("我是"+Name+"我的年龄是:"+Age);

                            Console.ReadKey();

                   }

         }

 

 

5、不借助于Dreamweaver、VisualStudio等开发工具,使用记事本等文本编辑器编写下面的HTML页面:

<html>

      <head>

           <title>登录</title>

<style type="text/css">

#tb{

        border-bottom:1px solid #000;

        border-right: 1px solid #000;

}

 

#tb td,th{

         border-top: 1px solid #000;

        border-left: 1px solid #000;

}

.centerz{text-align:center;}

 

.left{text-align:right;}

</style>

      </head>

<body>

<form>

<table cellspacing=0 cellpadding=13 id="tb">

<tr >

<th colspan="2" >必填信息</td>

</tr>

<tr>

<td class="left">登录名</td>

<td><input type="text" />(只能用英文、数字和下划线)</td>

</tr>

<tr>

<td class="left">密码</td>

<td><input type="password"/>(密码必须大于5位,区分大小写)</td>

</tr>

<tr>

<td class="left">确认密码</td>

<td><input type="password"/></td>

</tr>

<tr>

<td class="left">邮件地址</td><td><input type="text" /></td>

</tr>

<tr>

<td class="left">确认邮件地址</td><td><input type="text" /></td>

</tr>

<tr>

<td colspan="2" class="centerz"><input type="submit" value="提交"/><input type="reset" value="重填"/></td>

</tr>

<tr >

<td colspan="2" ></td>

</tr>

</table>

</form>

</body>

</html>

 

 

6、使用JavaScript验证第5题的HTML表单。要求如下:“登录名”必须是字母数字或下划线, 不能以数字开头;密码为6-16位字母、数字或者下划线.;密码和确认密码一致;邮件地址是正确的邮件地址格式;邮件地址和确认邮件地址一致;。(选做题 20分)

posted @ 2012-03-19 17:21  51秒懂  阅读(295)  评论(0编辑  收藏  举报