欢迎来到天天文库
浏览记录
ID:39549582
大小:43.00 KB
页数:5页
时间:2019-07-06
《c#考试程序复习资料》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、冒泡排序:inttemp=0;Console.WriteLine("请输入元素的个数);intcount=int.Parse(Console.ReadLine());int[]arr=newint[count];for(inti=0;iarr[j+1]){//交换
2、元素temp=arr[j];arr[j]=arr[j+1];arr[j+1]=temp;}}}for(inti=0;i3、=int.Parse(Console.ReadLine());if(a+b>c&&a+c>b&&b+c>a){if(a*a+b*b==c*c4、5、a*a+c*c==b*b6、7、b*b+c*c==a*a){Console.WriteLine("可以构成直角三角形");}else{Console.WriteLine("可以构成三角形,但不能构成直角三角形");}}else{Console.WriteLine("不能构1成三角形");}Console.ReadLine();定义一个类:person.csusingSystem;usingSystem.Collections.Generic;us8、ingSystem.Text;namespaceCon{classperson{publicstringname;//1.写成员变量。2.构造函数(先写无参构造函数)。3.写属性。intage;//4.写方法。5.方法的重载。6.实名化对象publicstringsex;publicintAge//属性{get{returnage;}set{if(value>0&&value<100){age=value;}else{age=18;}}}publicperson(){}publicperson(stringname,stringsex){this.name=name;this.sex9、=sex;}publicvoidsayHI()//方法{if(this.sex=="女"){Console.WriteLine("你好,我是女生,我叫"+name);}else{Console.WriteLine("我是男生,我叫"+name);}}publicstringcompare(){if(this.age>40){return"老人";}else{return"青年";}}publicstringcompare(inta){if(this.age>a){return"比他大";}else{return"比他小";}}publicstaticvoidcompare(perso10、na,personb){if(a.age>b.age){Console.WriteLine(a.name+""+"大");}else{Console.WriteLine(b.name+""+"大");}}}}Program.csusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingCon;//命名空间不同,用using组织。namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){personzhang=newperson(11、"张","女");zhang.Age=50;personli=newperson("李","男");li.Age=20;zhang.sayHI();li.sayHI();Console.WriteLine(zhang.name+""+zhang.compare());Console.WriteLine(li.name+""+li.compare());Console.WriteLine(zhang.compare(li.Age));person.compa
3、=int.Parse(Console.ReadLine());if(a+b>c&&a+c>b&&b+c>a){if(a*a+b*b==c*c
4、
5、a*a+c*c==b*b
6、
7、b*b+c*c==a*a){Console.WriteLine("可以构成直角三角形");}else{Console.WriteLine("可以构成三角形,但不能构成直角三角形");}}else{Console.WriteLine("不能构1成三角形");}Console.ReadLine();定义一个类:person.csusingSystem;usingSystem.Collections.Generic;us
8、ingSystem.Text;namespaceCon{classperson{publicstringname;//1.写成员变量。2.构造函数(先写无参构造函数)。3.写属性。intage;//4.写方法。5.方法的重载。6.实名化对象publicstringsex;publicintAge//属性{get{returnage;}set{if(value>0&&value<100){age=value;}else{age=18;}}}publicperson(){}publicperson(stringname,stringsex){this.name=name;this.sex
9、=sex;}publicvoidsayHI()//方法{if(this.sex=="女"){Console.WriteLine("你好,我是女生,我叫"+name);}else{Console.WriteLine("我是男生,我叫"+name);}}publicstringcompare(){if(this.age>40){return"老人";}else{return"青年";}}publicstringcompare(inta){if(this.age>a){return"比他大";}else{return"比他小";}}publicstaticvoidcompare(perso
10、na,personb){if(a.age>b.age){Console.WriteLine(a.name+""+"大");}else{Console.WriteLine(b.name+""+"大");}}}}Program.csusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingCon;//命名空间不同,用using组织。namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){personzhang=newperson(
11、"张","女");zhang.Age=50;personli=newperson("李","男");li.Age=20;zhang.sayHI();li.sayHI();Console.WriteLine(zhang.name+""+zhang.compare());Console.WriteLine(li.name+""+li.compare());Console.WriteLine(zhang.compare(li.Age));person.compa
此文档下载收益归作者所有