资源描述
复习题
一、 填空题(每空2分)
1、为使c#源程序能够编译和执行,必须安装 。
2、c#中的三元运算符是 。
3、类组员的可访问形式为___________、_______________、______________。
4、当整数a赋值给一个object对象时,整数a将会被 。
5、float f=263.981F;
int i=(int)f;
i的值是 。
6、面对对象的语言具备__________性、__________性和__________性。
7、ADO.NET中的五个重要对象_______________、_____________、_______________、_______________、_________________。
二、 写出下列程序运行成果(每题6分)
1、
using System;
class jieguo1
{
public static void Main()
{
bool x;
int y=10,z=3;
uint i=8,j=65535;
x=(y<z*4);
Console.WriteLine(“x={0}”,x);
y/=8;
Console.WriteLine(“y={0}”,y);
i=j>>2;
Console.WriteLine(“i={0}”,i);
}
}
2、
using System;
class jieguo2
{
public static void Main()
{
int a,x,y;
string z;
Console.WriteLine(“请输入一个整数:“);
z= Console.ReadLine();
x=Int32.Parse(z);
if(x<0) a=-1;
else a=x/10;
switch(a)
{
case -1:y=0;break;
case 0:y=x;break;
case 1:y=10;break;
case 2:
case 3:y=(int)(-0.5*x+30);break;
default:y=-2; break;
}
if (y!=-2) Console.WriteLine(“y={0}”,y);
else Console.WriteLine(“error!”);
}
}
x=10; y是:
x=-10;y是:
x=40; y是:
3、
using System;
class jieguo3
{
public static void Main()
{
string aa=”这是第一\t行,\n这是\\\\第二行.\n这是第\”三\”行”;
string bb=@”这是第一\t行,\n这是\\\\第二行.\n这是第\”三\”行”;
Console.WriteLine(“aa为:”);
Console.WriteLine(aa);
Console.WriteLine(“bb为:”);
Console.WriteLine(bb);
}
}
4、
using System;
public class jieguo4
{
public static void Main()
{
int[][] myArray = new int[2][];
myArray[0] = new int[5] {1,3,5,7,9};
myArray[1] = new int[4] {0, 2, 4, 6};
for (int i=0; i < myArray.Length; i++)
{ Console.Write("第({0})个数组: ", i);
for (int j=0; j < myArray[i].Length; j++)
{
Console.Write("{0} ", myArray[i][j]);
}
Console.WriteLine();
}
}
}
5、
using System;
class jieguo5
{
public static void Main()
{
int varA = 10;
int varB = 20;
int andResult = varA & varB;
Console.WriteLine("10 & 20 = {0}", andResult);
int orResult = varA | varB;
Console.WriteLine("10 | 20 = {0}", orResult);
int notorResult = varA ^ varB;
Console.WriteLine("10 ^ 20 = {0}", notorResult);
Console.WriteLine("~ {0:x8} = {1:x8}", varA, ~varA);
}
}
6、
using System;
class jieguo6
{
public static void Main()
{
int i=1,sum=0;
while(i<=100)
{
sum +=i;
i++;
}
Console.WriteLine(“sum=”,sum);
}
}
7、
using System;
class jieguo7
{
public static void Main()
{
int i,j,k,m;
int[] queArray = new int[]{5,2,8,12,36,24,88,1,103,69};
for(j=0;j<queArray.Length;j++)
{
k=j;
for(i=j+1;i<10;i++)
{
if(queArray[i]<queArray[k]) k=i;
}
if(k!=j)
{
m=queArray[j];
queArray[j] = queArray[k];
queArray[k] = m;
}
}
for(j=0;j<10;j++)
{
Console.Write("{0} ", queArray[j]);
}
}
}
8、
using System;
public class jieguo8
{
static void Add(int i)
{
i++;
}
static void AddWithRef(ref int i)
{
i++;
}
public static void Main()
{
int i1 = 10;
int i2 = 20;
Add(i1);
AddWithRef(ref i2);
Console.WriteLine(“i1=”+i1);
Console.WriteLine(“i2=”+i2);
}
}
9、
三、 指出程序或函数的功效(每题6分)
1、
using System;
class gongneng1
{
public static void Main()
{
for(int i=0;i<15;i++)
{
if(i==12) continue;
Console.WriteLine(“i={0}”,i);
}
}
}
2、
using System;
class gongneng2
{
public static void Main()
{
for(int i = 1; i <= 9; i++)
{
for(int j = 1; j <= i; j++)
{
Console.Write("{0}x{1}={2}\t", i, j, i*j);
}
Console.WriteLine();
}
}
}
3、
using System;
class gongneng3
{
public static void Main(String[] args)
{
string strName;
strName = args[0];
Console.WriteLine("This is the first argument: {0}!", strName);
}
}
4、
using System;
class gongneng4
{
public static int Main(string[] args)
{
if(args.Length < 1)
{
Console.WriteLine("Usage: ifApp char");
return 1;
}
char chLetter = args[0][0];
if(chLetter >= 'A')
{
if(chLetter <= 'Z')
{
Console.WriteLine("{0} 是个大写字母", chLetter);
return 0;
}
}
if(chLetter >= 'a' && chLetter <= 'z')
{
Console.WriteLine("{0} 是个小写字母", chLetter);
return 0;
}
if(Char.IsDigit(chLetter))
{
Console.WriteLine("{0} 是个数字", chLetter);
return 0;
}
Console.WriteLine("{0} 是个特殊字符", chLetter);
return 1;
}
}
5、
using System;
class gongneng5
{
public static void Main()
{
float[] a= new float[] {82,90,78,63,75,94,87,86,99,71};
int i;
float s=0,aver,max=0,min=100;
for(i=0;i<10;i++)
{
if(a[i]>max) max=a[i];
if(a[i]<min) min=a[i];
s=s+a[i];
}
aver=s/10;
Console.WriteLine("max = {0}", max);
Console.WriteLine("min = {0}", min);
Console.WriteLine("aver = {0}", aver);
}
}
6、
using System;
class gongneng6
{
public static void Main()
{
int s=1;
int n = Convert.ToInt32(Console.ReadLine());
if(n>=1)
{
for(int i=2;i<=n;i++)
{
s *= i;
}
}
Console.WriteLine("n!={0}", s);
}
}
7、
using System;
class gongneng7
{
public static void Main()
{
char ch = (char) Console.Read();
switch(ch.ToLower())
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
Console.WriteLine("字母{0}是元音字母", ch);
break;
default :
Console.WriteLine("字母{0}是辅音字母", ch);
break;
}
}
}
四、 编程题(每题10分)
1、 请学生通过键盘输入行数和列数,然后打出一个由星号组成的方阵。(10分)
例如:输入行号 3
输入列号 3
成果为:* * *
* * *
* * *
2、一列数的规则如下: 1、1、2、3、5、8、13、21、34......
求第30位数是多少, 用递归算法实现。(10分)
3、由程序随机产生10个数,并把这10个数按从小到大的次序输出。
4、输出如下所示的九九乘法表。
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
……
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
展开阅读全文