diff --git "a/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" "b/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e81d6f60c4297729d791cd036cc1de4a1985a71e --- /dev/null +++ "b/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" @@ -0,0 +1,202 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Work05._12; + +namespace ConsoleApp1 +{ + class Program + { + + + + static void Main(string[] args) + { + + Information student = new Information(); + + student.userName = "adamin"; + student.Password = "admin"; + student.PasswordAttributes = "英文字母"; + + student.call(); + } + + + + + static void Square() + { + //用户输入正方形边长,用*打印出实心正方形。 + Console.WriteLine("请输入正方形的边长数:"); + int a = int.Parse(Console.ReadLine()); + string[,] arr = new string[a, a]; + for (int i = 0; i < a; i++) + { + for (int j = 0; j < a; j++) + { + arr[i, j] = "*"; + } + } + for (int i = 0; i < a; i++) + { + Console.WriteLine(); + for (int j = 0; j < a; j++) + { + Console.Write(arr[i, j]); + + } + } + + } + + //九九乘法表 + static void nine() + { + string[,] arr = new string[9, 9]; + for (int i = 0; i < arr.GetLength(0); i++) + { + for (int j = 0; j <= i; j++) + { + arr[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (i + 1) + "\t"; + } + } + + for (int i = 0; i < arr.GetLength(0); i++) + { + Console.WriteLine(); + for (int j = 0; j < arr.GetLength(1); j++) + { + Console.Write(arr[i, j]); + + } + } + + } + //static void nine2() + //{ + // int[][] arr2= new int[9][]; + // for (int i = 0; i < arr2.GetLength(0); i++) + // { + // for (int j = 0; j <= i; j++) + // { + // arr2[i, j] = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (i + 1) + "\t"; + // } + // } + + // for (int i = 0; i < arr2.GetLength(0); i++) + // { + // Console.WriteLine(); + // for (int j = 0; j < arr2.GetLength(1); j++) + // { + // Console.Write(arr2[i, j]); + + // } + // } + + //} + + static void HollowSqune() + { + //用户输入正方形边长,用*打印出空心正方形。 + Console.WriteLine("请输入空心正方形的边长数:"); + int a = int.Parse(Console.ReadLine()); + string[,] arr = new string[a, a]; + for (int i = 0; i < arr.GetLength(0); i++) + { + for (int j = 0; j < arr.GetLength(1); j++) + { + if (i == 0 | i == arr.GetLength(0) - 1) + { + arr[i, j] = "*"; + } + else + { + if (j == 0 || j == arr.GetLength(1) - 1) + { + arr[i, j] = "*"; + } + else + { + arr[i, j] = " "; + } + } + Console.Write(arr[i, j]); + + } + Console.WriteLine( ); + } + } + + + + //菱形 + static void rhombus() + { + Console.WriteLine("请输入菱形的边长数:"); + int a = int.Parse(Console.ReadLine()); + string[,] arr = new string[a, a]; + for (int i = 0; i < a; i++) + { + for (int j = 0; j < a; j++) + { + arr[i, j] = "*"; + } + } + } + + //在 Main 方法中创建一个字符串类型的数组,并存入 5 个值,然后将数组中下标是偶数的元素输出。 + static void index() + { + int[] arr = { 1, 50, 3, 45, 5 }; + int[] a = new int[5]; + for (int i = 0; i < arr.GetLength(0); i++) + { + if (arr[i] % 2 == 0) + { + a[i] = arr[i]; + Console.WriteLine(a[i]); + } + } + } + + //如果一个数组保存元素是有序的(从大到小), + //向这个数组中插入一个数,使得插入后的数组元素仍然保持有序。 + static void sort() + { + int[] arr = { 100, 80, 54, 50, 8 }; + int[] arr1 = new int[arr.Length + 1]; + Console.WriteLine("原数组:100, 80, 54, 50, 8"); + + for (int i = 0; i < 5; i++) + { + arr1[i] = arr[i]; + } + Console.WriteLine("这个数组中插入一个数"); + arr1[arr1.Length - 1] = int.Parse(Console.ReadLine()); + + + for (int i = 0; i < arr1.GetLength(0); i++) + { + for (int j = 0; j < arr1.GetLength(0) - 1; j++) + { + if (arr1[j] < arr1[j + 1]) + { + int b = arr1[j]; + arr1[j] = arr1[j + 1]; + arr1[j + 1] = b; + } + } + } + Console.Write("新数组:"); + foreach (var item in arr1) + { + + Console.Write(item + " "); + } + } + } +} + diff --git "a/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/information.cs" "b/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/information.cs" new file mode 100644 index 0000000000000000000000000000000000000000..aabc214c8dcb0f8bb6bf8e36797764a6fde24d8a --- /dev/null +++ "b/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/information.cs" @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Work05._12 +{ + class Information + { + //定义一个用户类,存放用户的账号、用户名和密码属性; + + public string userName { get; set; } + public string Password { get; set; } + public string PasswordAttributes { get; set; } + + public void call() + { + Console.WriteLine("我的账号是{0},我的密码是{1},我的密码属性是{2}", this.userName, this.Password, this.PasswordAttributes); + } + } +} diff --git "a/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..8e76ff26a73af8229373b4e5758c90944bda62a7 --- /dev/null +++ "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/Program.cs" @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class Program + { + static void Main(string[] args) + { + Test6(); + + } + + //要求用户输入半径的值,打印出以此值为半径的圆的面积 + //求圆的面积的公式:πr²。 + //π取3.14。 + //r由用户输入并存入一个变量中,此变量用double比较合适,因为用户可能会输入小数。 + static void Test() + { + Console.WriteLine("请输入圆的半径:"); + double r = double.Parse(Console.ReadLine()); + + double pai = 3.14; + + double result = pai * r * r; + Console.WriteLine("圆的面积是:"+result); + } + + static void Test1() + { + int[] arr = new int[5]; + int[] arr1 = { 1,2,2}; + arr[0] = 123; + arr[1] = 123; + arr[2] = 123; + + int key = 0; + switch (key) + { + case 1: + Console.WriteLine(); + break; + + case 2: + + case 3: + + default: + break; + } + + } + + //规范的多维数组 + public static void Test3() + { + int[,] arr2 = new int[5, 3];//5个一位数组,每个一维数组长度是3 + + arr2[0, 0] = 1; + arr2[0, 1] = 1234; + arr2[0, 2] = 546; + arr2[1, 0] = 967; + arr2[1, 1] = 64; + arr2[1, 2] = 87; + arr2[2, 0] = 967; + arr2[2, 1] = 64; + arr2[2, 2] = 87; + + + int[,] arr3 = { { 1, 2 }, { 1, 2 }, { 1, 2 } }; + for (int i = 0; i < arr2.GetLength(0); i++) + { + for (int j = 0; j < arr2.GetLength(1); j++) + { + Console.Write(arr2[i, j] + " "); + } + Console.WriteLine(); + } + + } + + //不规则的数组 + public static void Test4() + { + int[][] arr = new int[3][]; + + arr[0] = new int[] { 1 }; + arr[1] = new int[] { 1,2 }; + arr[2] = new int[] { 1,2,3 }; + + for (int i = 0; i < arr.Length; i++) + { + for (int j = 0; j < arr[i].Length; j++) + { + Console.WriteLine(arr[i][j]); + } + } + } + + public static void Test5() + { + int[] arr = {10,50,5,55,90 }; + + Console.WriteLine("排序前:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Console.WriteLine(); + + Array.Sort(arr); + + Console.WriteLine("排序后:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + } + + public static void Test6() + { + int[] arr = { 10, 50, 5, 55, 90 }; + + Console.WriteLine("排序前:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Console.WriteLine(); + + Array.Sort(arr); + + Console.WriteLine("排序后:"); + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Console.WriteLine(); + + + Console.WriteLine("反转后:"); + Array.Reverse(arr); + + foreach (var item in arr) + { + Console.Write(item + "|"); + } + + string str = "asdf4654sfgaf"; + foreach (var item in str) + { + Console.Write(item+" - "); + } + + //for (int i = 0; i < arr.Length; i++) + //{ + // Console.Write(arr[i] + " "); + //} + } + } +} diff --git "a/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..e5963c047acf862f21f8b81b0e229ad56ba4cd7c --- /dev/null +++ "b/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/Program.cs" @@ -0,0 +1,142 @@ +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) + { + word1(); + word2(); + word3(); + word4(); + word5(); + } + static void word1() + { + //输入一行字符串,分别统计出其中英文字母、数字、空格的个数。 + Console.WriteLine("请输入一行字符串:"); + string arr = Console.ReadLine(); + int word = 0; + int num = 0; + int whritespace = 0; + foreach (char item in arr) + { + if (char.IsLetter(item)) + { + word++; + } + else if (char.IsDigit(item)) + { + num++; + } + else if (char.IsWhiteSpace(item)) + { + whritespace++; + } + } + Console.WriteLine("输入的一行字符串中有英文字母{0}个、数字{1}个、空格{2}个", word, num, whritespace); + } + static void word2() + { + //用户输入三个数,找出最大的数,打印输出。 + Console.WriteLine("请输入第一个数:"); + int num1 = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第二个数:"); + int num2 = int.Parse(Console.ReadLine()); + Console.WriteLine("请输入第三个数:"); + int num3 = int.Parse(Console.ReadLine()); + int max; + + if (num1 > num2) + { + if (num1 > num3) + { + max = num1; + } + else + { + max = num3; + } + } + else + { + if (num2 > num3) + { + max = num2; + } + else + { + max = num3; + } + } + Console.WriteLine("最大的数为" + max); + + } + static void word3() + { + /* + 编写一个程序,请用户输入一个四位整数,将用户输入的四位数的千位、百位、十位和个位分别显示出来, + 如5632,则显示“用户输入的千位为5,百位为6,十位为3,个位为2” + */ + Console.WriteLine("请输入一个四位整数:"); + int num = int.Parse(Console.ReadLine()); + int qianwei = (num / 1000) % 10; + int baiwei = (num / 100) % 10; + int shiwei = (num / 10) % 10; + int gewei = (num / 1) % 10; + Console.WriteLine("用户输入的千位为" + qianwei + " ," + "百位为" + baiwei + " ," + "十位为" + shiwei + " , " + "各位" + gewei); + } + static void word4() + { + /* + 在 Main 方法中创建一个 double 类型的数组,并在该数组中存入 5 名学生的考试成绩,计算总成绩和平均成绩。 + 要求使用foreach语句实现该功能, + */ + double[] arr = new double[5]; + for (int i = 0; i < arr.Length; i++) + { + Console.WriteLine("请输入第" + (i + 1) + "名同学的考试成绩"); + arr[i] = double.Parse(Console.ReadLine()); + } + double sum = 0; + double avg = 0; + foreach (var item in arr) + { + sum = sum + item; + avg = sum / 5; + } + Console.WriteLine("总成绩为:" + sum); + Console.WriteLine("平均成绩为:" + avg); + } + + static void word5() + { + //定义一个方法,实现一维数组的排序功能,从大到小排序。 + int[] arr = new int[5]; + for (int i = 0; i < arr.Length; i++) + { + Console.WriteLine("请输入第" + (i + 1) + "个数"); + arr[i] = int.Parse(Console.ReadLine()); + return5(arr); + } + Console.Write("从大到小排序为"); + foreach (var item in arr) + { + Console.Write(item+" "); + } + + } + static void return5(int[] arr) + { + Array.Sort(arr); + Array.Reverse(arr); + + } + } +}