你的位置:首页 > ASP.net教程

[ASP.net教程]Asp_基础之C#基础


1、两个练习题

  1)编程实现46天,是几周几天

  int days = 46;

  int weeks = days / 7;

  int day =days % 7;

  //Console.WriteLine(weeks);

  //Console.WriteLine(day);

  Console.WriteLine("{0}些天是{1}个周{2}天",days,weeks,day);

 

  2)实现107653秒是几天几时几秒

  int seconds = 107653;

  int day = seconds / 86400;

  int secs = second % 86400;

  int hour = secs / 3600;

  secs = sec % 3600;

  int mins = secs / 60;

  secs = secs % 60;

  Console.WriteLine("{0}天{1}小时{2}分钟",day,hour,mins);

 

2、类型转换

Convert类型转换

eg:

  string s  = “123”;

  double b = Convert.ToDouble(s);

  int n = Convert.ToInt32(s);

  Console.WriteLine(b);

  Console.WriteLine(n);

注意:字符串中又字母时,不会报错,但运行会语法错误

 

3、问题 

提示用户输入三门课的成绩(语文,数学,英语),然后给用户显示总成绩和平均分。

  Console.writeLine("请输入你的姓名:");

  string name = Console.ReadLine();

  Console.WriteLine("请输入你的语文成绩");

  string Chinese = Console.ReadLine();

  Console.WriteLine("请输入你的数学成绩");

  string Math  = Console.ReadLine();

  Console.WriteLine("请输入你的英语成绩");

   string English = Console.ReadLine();

  double doubleChinese = Convert.Double(Chinese);

  double doubleMath = Convert.Double(Math);

  double doubleEnglish = Convert.Double(English);

  Console.WriteLine("{0}你的总成绩是{1}平均分是{2}",name,doubleChinese+doubleMath+doubleEnglish,

  (doubleChinese+doubleMath+doubleEnglish)/3);