C#程序设计及基于工作过程的项目开发(高职)(谢世煊) 第2章.pptVIP

  • 10
  • 0
  • 约1.89万字
  • 约 85页
  • 2017-08-20 发布于广东
  • 举报

C#程序设计及基于工作过程的项目开发(高职)(谢世煊) 第2章.ppt

  2.1 任务一:学会使用已有资源 2.1.1 功能描述   本任务通过一个控制台应用程序,演示了C#.NET框架类中的几个常用的类,包括System.String、System.StringBuilder、System.Math和System.Random类。 2.1.2 代码展示   1 using System;   2 using System.Text;   3 namespace useClassPro   4 {   5 class Program   6 {   7 static void Main(string[] args)   8 {   9 StringBuilder former = new StringBuilder(原始字符串为: );   10 StringBuilder total;   11 string mutation1, mutation2, mutation3;   12 int a, b, c;   13 double discriminant, root1, root2, test;   14 Console.WriteLine(原始字符串为: \ + former + \);   15 Console.WriteLine(字符串长度为: + former.Length);   16 total = former.Append(ax^2+bx+c);   17 mutation1 = total.ToString().ToUpper();   18 mutation2 = mutation1.Replace(X, y);   19 mutation3 = mutation2.Substring(21,9);   20 Console.WriteLine(连接后的字符串为: + total);   21 Console.WriteLine(mutation1 -- 调用大写函数后: + mutation1);   22 Console.WriteLine(mutation2 -- 调用替代函数将X替代为y后: +mutation2);   23 Console.WriteLine(mutation3 -- mutation2的子串: + mutation3);   24 Console.WriteLine();   25 Console.WriteLine(请输入x^2的参数A:);   26 a = int.Parse(Console.ReadLine());   27 Console.Write(请输入x的参数B:);   28 b = int.Parse(Console.ReadLine());   29 Console.WriteLine(请输入方程的常数C:);   30 c = int.Parse(Console.ReadLine());   31 discriminant = Math.Pow(b, 2) - (4 * a * c);   32 root1 = ((-1 * b) + Math.Sqrt(discriminant)) / (2 * a);   33 root2 = ((-1 * b) - Math.Sqrt(discriminant)) / (2 * a);      34 Console.WriteLine(Root1: + root1);   35 Console.WriteLine(Root2: + root2);   36 Console.WriteLine();      37 Console.WriteLine(让我们尝试随机生成方程:);   38 System.Random gener

文档评论(0)

1亿VIP精品文档

相关文档