C#实验二实验报告_第1页
C#实验二实验报告_第2页
C#实验二实验报告_第3页
C#实验二实验报告_第4页
C#实验二实验报告_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

XXXXXXXXXX实验报告实验课程名称:面向对象的程序设计实验项目名称:实验二C#基本语法专业班级:XXXXXXXXXXXX学号:XXXXXXXXXX姓名:新浪微博:圣痕轨迹指导教师:XXX

实验二C#基本语法【实验目的】了解C#中的各种数据类型及其相互转换方法。了解C#中的常量和变量。掌握C#中的常用的操作符与表达式。进一步熟悉C#程序的开发过程。掌握C#中选择结构语句的使用。掌握C#中循环结构语句的使用。掌握C#中的跳转结构语句【实验内容及步骤】题目一:程序分析分析程序,写出程序的运行结果,并上机进行验证。usingSystem;publicclassBoolTest{publicstaticvoidMain(){Console.Write("请输入一个字符:");charc=(char)Console.Read();if(Char.IsLetter(c))if(Char.IsLower(c))Console.WriteLine("字符是小写的。");elseConsole.WriteLine("字符是大写的。");elseConsole.WriteLine("字符不是字母。");}}分析程序,写出程序的运行结果,并上机进行验证。usingSystem;classtest{publicstaticvoidMain(){stringa="\u0068ello";stringb="world";Console.WriteLine(a+b);Console.WriteLine(a+b=="helloworld");}}分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(){inta=10;Console.WriteLine("a={0}",a);intb=newint();Console.WriteLine("1:b={0}",b);b=10;Console.WriteLine("2:b={0}",b);Int32c=10;Console.WriteLine("c={0}",c);Int32d=newInt32();Console.WriteLine("1:d={0}",d);d=10;Console.WriteLine("2:d={0}",d);Console.WriteLine("int:{0}~~{1}",int.MinValue,int.MaxValue);Console.Read();}}}分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(){charc1='a';charc2='\x0062';charc3='\u0063';Console.WriteLine("c1:{0}\nc2:{1}\nc3:{2}\n",c1,c2,c3);Console.Read();}}}分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{enumWeekDay{sun,mon,tue,wed,thu,fri,sat}staticvoidMain(){WeekDaya=WeekDay.sun;Console.WriteLine(a);WeekDayb=(WeekDay)4;Console.WriteLine(b);Console.Read();}}}(6)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){int[][]jagArray=newint[2][]{newint[5],newint[3]};for(inti=0;i<jagArray.GetLength(0);i++){for(intj=0;j<jagArray[i].Length;j++)jagArray[i][j]=i+j;}for(intk=0;k<2;k++){Console.WriteLine("jagArray[{0}]:",k);for(intm=0;m<jagArray[k].Length;m++)Console.Write("{0,-3}",jagArray[k][m]);Console.WriteLine();}Console.Read();}}}(7)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){objectx;x=1;Console.WriteLine("1:x={0},typeis{1};",x,x.GetType());x=10.01;Console.WriteLine("2:x={0},typeis{1};",x,x.GetType());x='\u0061';Console.WriteLine("3:x={0},typeis{1};",x,x.GetType());x="Hello!";Console.WriteLine("4:x={0},typeis{1};",x,x.GetType());Console.Read();}}}(8)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){Console.Write("请输入1-12之间的任意一个整数:");strings=Console.ReadLine();intmonth=int.Parse(s);switch(month){case1:Console.WriteLine("January");break;case2:Console.WriteLine("February");break;case3:Console.WriteLine("March");break;case4:Console.WriteLine("April");break;case5:Console.WriteLine("May");break;case6:Console.WriteLine("June");break;case7:Console.WriteLine("July");break;case8:Console.WriteLine("August");break;case9:Console.WriteLine("September");break;case10:Console.WriteLine("October");break;case11:Console.WriteLine("Noveber");break;case12:Console.WriteLine("December");break;default:Console.WriteLine("输入错误,转换失败。");break;}Console.Read();}}}(9)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){int[,]a=newint[5,5];a[0,0]=1;for(inti=1;i<5;i++){a[i,0]=1;a[i,i]=1;for(intj=1;j<i;j++)a[i,j]=a[i-1,j-1]+a[i-1,j];}for(inti=0;i<5;i++){for(intj=0;j<=i;j++)Console.WriteLine("{0}\t",a[i,j]);Console.WriteLine();}Console.Read();}}}(10)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){intodd=0,even=0;int[]array=newint[]{0,4,7,8,9,10,14,17,19,24,56};foreach(intiinarray){if(i%2==0)even++;elseodd++;}Console.WriteLine("{0}个奇数,{1}个偶数",odd,even);}}}(11)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;publicclassTestDoWhile{publicstaticvoidMain(){intx;inty=0;do{x=y++;Console.WriteLine(x);}while(y<5);}}(12)分析程序,写出程序的运行结果,并上机进行验证。usingSystem;namespace_1{classProgram{staticvoidMain(string[]args){Console.WriteLine("---break---");for(inti

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论