From 971e4d8fa95c04066180b81a4249535dd1857c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E5=BF=A7?= <2486779710@qq.com> Date: Sun, 9 May 2021 22:57:54 +0800 Subject: [PATCH] first commit --- .../Program.cs" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" diff --git "a/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" new file mode 100644 index 0000000..b988baf --- /dev/null +++ "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Program + { + static void Main(string[] args) + { + Test5(); + } + //编写一个程序,请用户输入一个四位整数,将用户输入的四位数的千位、百位、十位和个位分别显示出来, + //如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” + static void Test1() + { + Console.WriteLine("请输入一个四位整数:"); + int num = int.Parse(Console.ReadLine()); + + Console.WriteLine("千位为:" + num / 1000); + Console.WriteLine("百位为:" + num % 1000 / 100); + Console.WriteLine("十位为:" + num % 100 / 10); + Console.WriteLine("个位为:" + num % 10); + } + //用户输入三个数,找出最大的数,打印输出 + static void Test2() + { + Console.WriteLine("请输入第一个数:"); + int a = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第二个数:"); + int b = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第三个数:"); + int c = int.Parse(Console.ReadLine()); + + int d = a > b ? a : b; + int f = d > c ? d : c; + } + //输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 + static void Test3() + { + Console.WriteLine("请输入一行字符串:"); + string sr = Console.ReadLine(); + int a = 0; + int b = 0; + int c = 0; + foreach (char item in sr) + { + if (char.IsLetter(item)) + { + a++; + } + else if (char.IsDigit(item)) + { + b++; + } + else if (char.IsWhiteSpace(item)) + { + c++; + } + } + Console.WriteLine("字符串中英文字母有{0}个,数字有{1}个,空格有{2}个",a,b,c); + } + //在 Main 方法中创建一个 double 类型的数组,并在该数组中存入 5 名学生的考试成绩,计算总成绩和平均成绩。 + //要求使用foreach语句实现该功能, + static void Test4() + { + double[] arr = {85,96,93,89,95}; + double sum = 0; + foreach (var item in arr) + { + sum = sum + item; + } + Console.WriteLine("总成绩为{0},平均成绩为{1}",sum,sum/5); + } + //定义一个方法,实现一维数组的排序功能,从大到小排序。 + static void Test5() + { + int[] arr = { 25, 36, 65, 24, 54 }; + Console.WriteLine("排序前:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Array.Sort(arr); + Array.Reverse(arr); + Console.WriteLine(); + Console.WriteLine("排序后:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + } + } +} -- Gitee