




已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
四、读程序写结果和看程序填空2、class Program static void Main(string args) Elephant e = new Elephant(abc); Console.ReadLine(); public class Animal public Animal() Console.Write (基类默认构造函数!); public Animal(string s) Console.Write (非默认构造函数); public class Elephant : Animal public Elephant() Console.Write (派生类构造函数!); public Elephant(string str) : base(str) Console.Write (str); 程序的运行结果是_非默认构造函数abc _3.在Main方法中需要调用Display方法,按照要求填空 class Program static void Main(string args) A1 a = new A1(); /创建A1类的对象a Console.WriteLine(a.Display(); Console.ReadLine(); class A1 public string Display() return hello everyone!; 4、下列程序完成了调用静态方法和实例方法,补充空白处并写出运行结果class Program static void Main(string args) Example e1 = new Example(); e1.meth1(); Example.meth2(); /调用meth2() Console.WriteLine(a=0,b=1,e1 .a ,Example .b); Console.ReadLine(); class Example public int a; static public int b; public void meth1() a = 10; b = 20; public static void meth2() b = 30; 程序的输出结果是_a=10,b=30_5、 class Program static void Main(string args) s s1 = new s(); s t1 = new s(); Console.ReadLine(); public class s public s() Console.Write (构造函数!); static s() Console .Write (静态构造函数!); 程序的运行结果是_静态构造函数!构造函数!构造函数!_6、 class Program static void Main(string args) Person p = new Person(); p.N = www; Console.WriteLine(p.N ); Console.ReadLine(); public class Person private string p_name=abc; public string N get return p_name; set p_name = value; 程序最终的输出结果是_www_7、class Program static void Main(string args) B b = new B(); A a = b; a.G(); b.G(); Console.Read(); class A public virtual void G() Console.Write (A.G!); class B : A public override void G() Console.Write (B.G!); 程序的输出结果是_ B.G!B.G!_8、下列程序完成了输出数组中的最大值和最小值,请补充程序中的空白处class Program static void Main(string args) MyClass m = new MyClass(); int s = 1, 6, 4, 7, 3, 87, 5 ; int smax, smin; m.MaxMin(s, out smax, out smin); Console.WriteLine(smax=0,smin=1,smax ,smin ); Console.ReadLine(); class MyClass public void MaxMin(int a, out int max, out int min) max = min = a0; for (int i = 1; i max) max = ai; if (ai y) tmp = x; x = y; ;y = tmp; if (x t) tmp = x; x = t; t = tmp; if (y t) tmp = y; y = t; t = tmp; Console.WriteLine(0,1,2, x, y, t); 程序的输出结果是_ a=0,b=10,c=20 _14、 class Program static void Main(string args) MyClass m = new MyClass(); int s = 34, 23, 65, 67, 54, 98, 6, 56 ; m.Array(s); for(int i=0;is.Length ;i+) Console .Write(0,s i); Console .ReadLine (); class MyClass public void Array(int a) for (int i = 0; i 0); Console.WriteLine(sum = 0, sum); 程序的运行结果是_ sum = 1_17、static void Main(string args) int x = 123;object obj1=x; x = x+100; Console.WriteLine ( obj1= 0 , obj1 ); 程序的输出结果是_ obj1=123_18、下面程序的功能是:输出100以内能被3整除且个位数为6的所有整数,请填空。 static void Main(string args) int j; for (int i = 0; i = 9; i+) j = i * 10 + 6; if (i % 10 !=6&j%3!=0) Continue; Console.Write(t0,j); Console.Read(); 19、using System;class Program static void Main(string args) int m, n, i, j, max = 0; Console.WriteLine(请输入m,n的值); m = Convert.ToInt32(Console.ReadLine (); n = int.Parse(Console.ReadLine(); if (m 0; j-) if (m % j = 0 & n % j = 0) max = j; break; Console.WriteLine(max=0, max); Console.ReadLine(); 若分别从键盘输入8和6,则程序的运行结果是_ max=2_ 20、static void Main(string args) int Sum = 0; for (int i = 1; i = 10; i+) if (i % 2 = 0) Sum += i; Console.WriteLine(Sum); 程序的输出结果是_30_21、 static void Main(string args) int m, n,i; int a = new int61,2,5,3,9,7; m = n = a0; for (i = 1; i max) m = ai; if (ai min) n = ai; Console.WriteLine(0, 1,m,n ); Console.ReadLine(); 程序最终的输出结果是_9,1_22、class Program static void Main(string args) for (int i = 1; i = 10; i+) Console.Write(i); if (i % 5 = 0) Console.WriteLine(); else Console.Write(t); 程序的运行结果是_1 2 3 4 56 7 8 9 10_23、static void Main(string args) int Sum = 0; for (int i = 1; i 0) case true : switch (b 10) case true: Console.Write(); break; case false: Console.Write(!); break; break; case false : switch (c = 5) case false: Console.Write(*); break; case true: Console.Write(#); break; break; Console.Read(); 程序最终的输出结果是_ _25、 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(Exception!); finally Console.WriteLine(thank you for using the program!); Console.ReadLine(); 若分别从键盘上输入5和x,则程序的最终执行结果是格式不符thank you for using the program!26、 class Program static void Main(string args) Taxi t = new Taxi(); Console.WriteLine(t.isInitialized ); Console.ReadLine(); public class Taxi public bool isInitialized = false; public Taxi() isInitialized = true; 程序最终的输出结果是_ True _27、class Program static void Main(string args) Mouse m = new Mouse(); m.Eat(); m.Sleep(); public abstract class Animal public abstract void Sleep(); public virtual void Eat() Console.Write (eat something); public class Mouse : Animal public override void Sleep() Console.Write (mouse sleeping!); public override void Eat() Console.Write (eat cheese!); 程序的输出结果是_ eat cheese! mouse sleeping! _28、 class Program static void Main(string args) SharedClass sc = new SharedClass(); sc.SetDataA(interface IpartA); Console.ReadLine(); public interface IpartA void SetDataA(string dataA); public class SharedClass : IpartA private string DataA; private string DataB; public void SetDataA(string dataA) DataA = dataA; Console.WriteLine(0, DataA); 程序最终的输出结果是interface IpartA _29、 static void Main(string args) int m, n, i, j, s= 0; Console.WriteLine(请输入m,n的值); m = Convert.ToInt32(Console.ReadLine (); n = int.Parse(Console.ReadLine(); if (m 0; j+) if (j % m = 0 & j % n = 0) s = j; break; Console.WriteLine(0, s); 若从键盘上分别输入4和6,则程序最终的输出结果是_12_30、static void Main(string args) int pins = 9, 3, 7, 2 ;for (int index = 0; index != pins.Length; index+) int pin = pinsindex; System.Console.Write (pin);foreach (int i in pins)Console.Write (i); 程序的输出结果是_93729372_31、分析一下C#代码,根据面向对象的多态性,代码的运行结果是_B_class Apublic void F()Console.Write(“A”); Public void F(string chr)Console .Write(“B”);class B:APublic void F()Console.write(“B”);Static void Main()B objB=new B();objB.F(); 32、分析如下C# 代码,根据类的继承关系,运行后的输出结果是_不得入内 未成年人_public class Personprivate int age=0;public int Agegetreturn age;setIf(value=18)Console.WriteLine(“成年人”);ElseConsole.WrteLine(“未成年人”);public class People:Personpublic People()Console.Write(“不得入内”);class Teststatic void Main (stringargs)people shang=new People();shang.Age=1733、阅读下面程序,请确定枚举成员的关联值。enum Color:uint Red, Green=3, Blue, Max=Blue(1) 枚举成员Red的关联值为(0)(2) 枚举成员Green的关联值为(3)(3) 枚举成员Blue的关联值为(4)(4) 枚举成员Max的关联值为(4)。34、写出以下程序的运行结果。_57_using System;class Test public static void Main() int x = 5; int y = x+; Console.Write (y); y=+x; Console.Write (y); 35、写出下列函数的功能。若AB则返回1,若A=B则返回0,若Ab) return 1; else if (a=b) return 0; else return -1; 36、写出以下程序运行结果。9 12 15using System;class Test static int a = 1, 2, 3, 4, 5, 6, 7, 8 ; public static void Main() int s0, s1, s2; s0 = s1 = s2 = 0; for (int i = 0; i 8; i+) switch (ai % 3) case 0: s0 += Test.ai; break; case 1: s1 += Test.ai; break; case 2: s2 += Test.ai; break; Console.WriteLine(s0 + + s1 + + s2); 37、写出以下程序的运行结果。2 4 6 8 10 12 14 16 18using System;class Test public static void Main () int a =2,4,6,8,10,12,14,16,18; for (int i=0; i50) break; if (i%2=0) s+=i; Console.WriteLine (i, s= + i + , + s); 39、写出下列程序的运行结果。static void Main(string args) string words = new string “a”,”b”,”c”; foreach ( string word in words) Console.WriteLine(word); 答: _abc_40、 完善如下程序:
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030年中国高温热障涂层行业市场发展调研及投资前景展望报告
- 2025至2030年中国铝电解电容器行业市场竞争态势及发展趋向分析报告
- 2025至2030年中国通脉颗粒行业市场研究分析及投资策略研究报告
- 铜矿资源开发与市场发展战略考核试卷
- 2025至2030年中国触控显示屏行业市场运行态势及竞争战略分析报告
- java中级笔试面试题及答案
- 四川水利职业技术学院《综合商务英语(四)》2023-2024学年第二学期期末试卷
- 齐鲁医药学院《供应链》2023-2024学年第二学期期末试卷
- 河南开封科技传媒学院《英文报刊阅读》2023-2024学年第二学期期末试卷
- 上饶卫生健康职业学院《国际教育动态》2023-2024学年第二学期期末试卷
- 2024年北京英语考试专题考题及详细答案
- 2025年全年日历含农历(1月-12月)
- 礼品行业供应链管理研究
- 2024年江苏省宿迁市中考地理试题(含答案)
- 《学前儿童健康教育》6-3学前儿童安全教育活动的组织与实施课件
- 大学生创业基础智慧树知到期末考试答案章节答案2024年湖北工业大学
- 2025年高考历史一轮复习复习学案(中外历史纲要上下册)11纲要下册第一单元:古代文明的产生与发展(解析版)
- 新人教小学四年级数学下册第6单元小数的加法和减法第1课时《小数的加减法(一)》示范教学设计
- 七年级语文下册第六单元《带上她的眼睛》课件
- 贝雷梁支架结构计算书
- 湖南省怀化市会同县2023-2024学年一年级下学期期末考试数学试题
评论
0/150
提交评论