.NET学习 数组测试题级及参考答案
来源:互联网 发布:3g软件开发工程师 编辑:程序博客网 时间:2024/05/16 14:28
1. 数组有没有length()这个方法? String有没有length()这个方法?
数组没有Length()方法,只有属性。String 有这个length()这个方法
2.请编程实现int[] max={6,5,2,9,7,4,0}冒泡排序算法?
代码节选 :
int[] max ={ 6, 5, 2, 9, 7, 4, 0 };
foreach (int a in max)
{
Console.Write(a + " ");
}
Console.WriteLine();
//冒泡排列
for (int i=1;i<max.Length;i++)
{
for (int j=0;j<max.Length-i;j++)
{
if (max[j]>max[j+1])
{
int temp=max[j];
max[j]=max[j+1];
max[j+1]=temp;
}
}
}
//排序后的数组
foreach (int a in max)
{
Console.Write(a + " ");
}
Console.WriteLine();
3.请写出程序的输出结果:
string[] aa = new string[5];
aa[0] = "33";
aa[5] = "66";
string s = "";
foreach (string m in aa)
{
s += m;
}
Console.WriteLine(s);
错误, aa[5]超出数组索引的最大范围。
4.产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。
int[] intArr=new int[100];
ArrayList myList=new ArrayList();
Random rnd=new Random();
while(myList.Count<100)
{
int num=rnd.Next(1,101);
if(!myList.Contains(num))
myList.Add(num);
}
for(int i=0;i<100;i++)
intArr[i]=(int)myList[i];
using System;
using System.Collections.Generic;
using System.Text;
//产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] array = new int[100]; //定义一个长度为100数组
for (int i = 0; i < array.Length; i++)
{
label://标签
Random Rnd = new Random();
int a = (int)Rnd.Next(1, 101);
array[i] = a; //产生随机数赋值给数组
for (int j = 0; j < i; j++)
{
//判断随机数是否有重复
if (array[j] == array[i])
{
goto label; //跳转执行到label,继续产生随机数
}
}
Console.Write(array[i] + " /t");//输出数组中的元素
}
}
}
}
5. 将int[24]数组a1中的第6个起的10元素复制到int[24]数组a2中
int[] al = new int[24] {1,2,3,4,5,6,7,8,9,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0 };
int[] a2 = new int[24];
Console.WriteLine("数组a1为:");
foreach (int a in al)
{
Console.Write(a + " ");
}
Console.WriteLine();
for (int i = 5; i < 10;i++ )
{
a2[i - 5] = al[i];
}
Console.WriteLine("数组a2为:");
foreach (int a in a2)
{
Console.Write(a+" ");
}
Console.WriteLine();
6. C#数组简单问题(每段代码的输出结果)
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication167
{
class Program
{
static void Main(string[] args)
{
int[] a1 = new int[] { 1, 2 };
int[] a2 = a1;
a2[1] = 5;
Console.WriteLine("{0} {1}", a1[0],a1[1]); 1,5
Console.WriteLine("{0} {1}", a2[0], a2[1]); 1,5
Console.ReadLine();
}
}
}
-----------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication168
{
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = a;
a = 5;
Console.WriteLine(a);
Console.WriteLine(b);
}
}
}
7. (单选)
int[][] myArray3=new int[3][]{new int[3]{5,6,2},new int[5]{6,9,7,8,3},new int[2]{3,2}}; myArray3[2][2]的值是()。
1. 9
2. 2
3. 6
4. 越界
8. 已知数组int[] max={6,5,2,9,7,4,0};用选择排序算法按降序对其进行排列,并返回数组
int[] max ={ 6, 5, 2, 9, 7, 4, 0 };
Console.WriteLine("排序前数组max为:");
foreach (int a in max)
{
Console.Write(a + " ");
}
Console.WriteLine();
for (int i = 0; i < max.Length-1; i++)
{
int M = i; //数组最大值的下标M
for (int j = i+1 ; j < max.Length; j++)
{
if (max[j] > max[M])
{
M = j;
}
}
int temp; //进行交换
temp = max[M];
max[M] = max[i];
max[i] = temp;
}
Console.WriteLine("按降序排序后数组max:");
foreach (int a in max)
{
Console.Write(a + " ");
}
Console.WriteLine();
- .NET学习 数组测试题级及参考答案
- .NET测试四面向对象基础及参考答案
- .NET测试四面向对象基础及参考答案
- .net面试整试题及参考答案【转】
- .net面试整试题及参考答案【转】
- .net面试整试题及参考答案
- Hadoop自测题及参考答案
- Hadoop自测题及参考答案
- 微软软件测试题和参考答案
- 微软经典面试测试题和参考答案
- 软件测试常考面试题及参考答案(待更新)
- 大学英语四级考试试题及参考答案
- c# 笔试题及参考答案大全
- 阿里巴巴公司DBA笔试题及参考答案
- 2012微软实习笔试题及参考答案
- 阿里巴巴公司 DBA笔试题及参考答案
- 微软经典面试测试题和参考答案(变态)
- 微软经典面试测试题和参考答案(变态)
- 装载嵌入式JBoss到Tomat中
- PHP注意事项(陆续更新)
- java来做CLI
- 在Ubuntu 10.04上部署Monodevelop和Eclipse
- 跟我一起写 Makefile 转贴
- .NET学习 数组测试题级及参考答案
- Visual Studio 2008 单元测试
- Extjx3文件的介绍
- MM5toGRADS生成的数据描述文件的说明
- FCK编辑器的使用
- 格式字符串
- 自问自答 4 [技术类] [.net].net2010 重载WndProc函数,实现窗体移动
- Linux内核防火墙的包过滤机制
- DOC使用dumpbin导入数据dll文件