1 using System;
2  using System.Collections.Generic;
3  using System.Linq;
4  using System.Text;
5
6 namespace ConsoleApplication1
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 //测试递归方法
13 int i = 1;
14 while (i < 30)
15 {
16 Console.Write(Reqursion(i) + "<|>");
17 i++;
18 }
19 Console.ReadKey();
20
21 //测试冒泡排序法
22 int[] nums = new int[] { 1, 7, 3, 5, 2 };
23 BubbleSort(nums);
24 Console.ReadKey();
25
26 //测试指定字符串出现指定字符数统计方法
27 CheckStr("(C)2010MicroYrscienceCopyr","c");
28 Console.ReadKey();
29 }
30
31 //实现1 1 2 3 5 8 13 ... N的递归方法
32 private static int Reqursion(int num)
33 {
34 if (num <= 0)
35 {
36 return 0;
37 }
38 else if (num > 0 && num < 3)
39 {
40 return 1;
41 }
42 else
43 {
44 return Reqursion(num - 1) + Reqursion(num - 2);
45 }
46 }
47
48 //冒泡排序法
49 private static void BubbleSort(int[] Nums)
50 {
51 int TmpNum;
52 for (int i = 0; i < Nums.Length; i++)
53 {
54 for (int j = 0; j < i; j++)
55 {
56 if (Nums[i] > Nums[j])
57 {
58 TmpNum = Nums[i];
59 Nums[i] = Nums[j];
60 Nums[j] = TmpNum;
61 }
62 }
63 }
64 Console.Write("\n\n");
65 for (int x = 0; x < Nums.Length; x++)
66 {
67 Console.Write(Nums[x].ToString()+"<|>");
68 }
69 }
70
71 //在指定字符串中查找指定字符出现次数
72 private static void CheckStr(string str1,string str2)
73 {
74 string str = str1.Replace(str2, null);
75 Console.Write("\n\n"+"字符串|" + str1 + "|中出现字符|" + str2 + "|的次数是|" + (str1.Length - str.Length));
76 }
77 }
78 }
79

 

 

 

 

 

posted on 2010-09-11 23:48  yrScience  阅读(777)  评论(0编辑  收藏  举报