内容发布更新时间 : 2025/1/7 10:30:05星期一 下面是文章的全部内容请认真阅读。
48、 下列程序的作用是求出所有的水仙花数。(所谓水仙花数是指这样的数:该数是三位数,其各位数字的立方和等于该数) using system; class Example1 {
static void Main(string[] args) {
int a, i, b, c, t;
for (i = 100; i <= 999; i++) { t = i;
a = t % 10; t = t / 10; b = t % 10; c = t / 10; if (i == a * a * a + b * b * b + c * c * c) Console.WriteLine(\ }
Console.ReadLine(); }}
49、public class TEApp{
public static void ThrowException(){
throw new Exception(); }
public static void Main(){
try{
Console.WriteLine(“try”); ThrowException(); }
catch(Exception e){
Console.WriteLine(“catch”); } finally{
Console.WriteLine(“finally”); } }
}上述C#代码运行结果是(try
catch finallyA)
50、分析如上的C#代码段,运行后将输出老师的名字叫小明 学生的名字叫小明 public class Teacher{
public Teacher (string name){
Console.WriteLine(“老师的名字叫”+ name);
}
}
public class Test:Teacher{
public Test(string name){
Console.WriteLine(“学生的名字叫”+ name); } }
static void Main(string[] args) { Test t=new Test(“小明”);} 51、class Test{
static void Main(){
try{
int a = 10; int b = 0; int c = a / b;
Console.WriteLine(c);
} catch{
Console.WriteLine(“出现错误”);
} finally{ Console.WriteLine(“运行结束”); }
}
}在C#中,上述代码的运行结果是出现错误
运行结束
52、下列程序是输出100以内所有能被7整除的数,请将程序补充完整。 using System; class Output { static void Main()
{for (int k=1;k<=100;___k++______ ) {if (k%7!=0) ; ____continue;________
Console.Write(_____k_______);}} } 53、写出下列函数的功能。求出从键盘上输入的一批常数的平均值,以-1作为结束输入的标志。static float FH() { float y=0,n=0;
int x = Convert.ToInt32(Console.ReadLine()); //从键盘读入整型数据赋给x while (x!=-1) { n++; y+=x;
x = Convert.ToInt32(Console.ReadLine()); } if (n==0) return y; else return y/n; }
54、写出以下程序运行结果。 25 10 25 10 using System; class Test {
static void LE(ref int a, ref int b) { int x = a; a = b; b = x;
Console.writeLine (a + “ “ +b); }
public static void Main () {
int x=10, y=25; LE(ref x, ref y);
Console.writeLine (x + “ “ +y); } }
55、阅读以下的C#代码:下述代码运行后,将在控制台窗口输出 A
B class A {
public A( )
{ Console.WriteLine(\ } } class B:A {
public B()
{ Console.WriteLine(\ } }
class Program {
public static void Main() {
B b = new B(); Console.ReadLine(); }
}
56、class Program {
static void Main(string[] args) {
Person p = new Person(); p.N = \
Console.WriteLine(p.N ); Console.ReadLine(); } }
public class Person {
private string p_name=\ public string N {
get { return p_name; } set { p_name = value; } } }
程序最终的输出结果是_________www____________________ 57、static void Main(string[] args)
{ try {
int x = Convert.ToInt32(Console.ReadLine()); int y = Convert.ToInt32(Console.ReadLine()); int z = x / y; }
catch (FormatException)
{Console.WriteLine(\格式不符\ catch (DivideByZeroException) { Console.WriteLine(\除数不能是0\ catch (Exception)
{Console.WriteLine(\ finally {
Console.WriteLine(\
}
Console.ReadLine();
}
若分别从键盘上输入5和x,则程序的最终执行结果是
58、程序执行后,m的值是 0 public int which(int k) { int x=0; Switch(k){
case 1: x=10;break; case 2: x=15;break; } return x; } ……
int m=which(5);
59、在C#中,下列代码的运行结果是(024)。 public static int Add(int a,int b) { a++; b++; return a+b;
}
static void Main() { int a=0; int b=2; int c = Add(a,b); Console.Write(a); Console.Write(b); Console.Write(c);
}
60、在C#中,下列代码的运行结果是(-5 )。 static void Main() { int i= showInfo(5,10,\ Console.WriteLine(i);
}
static int showInfo(int a,int b,string op) { if(op==\
return a+b; if(op==\
return a-b;
return a*b;
}
61、分析下列程序的功能,并指出运行结果。 using System; public class array1 {
public static void Main( ) {
int [ ] a={34,91,83,56,29,93,56,12,88,72}; int i,t=0,temp=100; for(i=0;i<10;i++) if(a[i] temp=a[i]; t=i; } Console.WriteLine(“{0} {1}”,temp,t); } } 运行结果: 12 7 . 62、写岀下面程序的运行结果 050055 class Program { static void Main(string[] args) { Class1 c1 = new Class1(); Class1.y = 5; c1.output(); Class1 c2 = new Class1(); c2.output(); Console.ReadLine(); } } public class Class1 { private static int x = 0; public static int y = x; public int z = y; public void output() { Console.Write (Class1.x); Console.Write (Class1.y); Console.Write (z); } } 63、运行结果: . static void Main(string[] args) { int x = 9; Console.WriteLine((x--) + (x--) + (x--)); Console.WriteLine(x); int y = (--x) + (--x) + (--x); Console.WriteLine(y); Console.WriteLine(x); Console.ReadLine(); } 64、程序的最终运行结果是110 150 199 30 18 static void Main(string[] args) { int[] myArray = { 110, 150, 199, 30, 18}; for (int i = 0; i != myArray.Length - 1;i++ ) { AddArray(myArray[i]); } foreach (int i in myArray) { Console.WriteLine(i); } } public static void AddArray(int num) { num += 1; } 65、下面代码是要显示My string, 请分析下列代码段并在空白行补全C#代码:static void Main(string[] args) { string myString = \ char[] myChars = myString.ToCharArray(); foreach (_____char character in myChars___________) { Console.WriteLine(\ } Console.ReadKey(); } 66、请写出该段代码的运行结果:____ False 2____ abstract class BaseClass { public virtual bool MethodA() { return true; } public virtual string MethodB() { return \ } } class Class1:BaseClass { public override bool MethodA() { return false; } public override string MethodB() { return \ } } class Class2:Class1 { new public string MethodB() { return \ } } class MainClass { public static void Main(string[] args) { Class2 o = new Class2(); Class2 q = new Class2(); Console.WriteLine(o.MethodA()); Console.WriteLine(q.MethodB());