zoukankan      html  css  js  c++  java
  • 线程Test1

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 
     5 using System.Threading;
     6 
     7 namespace ConsoleAppThread
     8 {
     9     /// <summary>
    10     /// 同时计算并输出整数10000的所有因子以及1-40的费波纳契级数
    11     /// </summary>
    12     class Program
    13     {
    14         static void Main(string[] args)
    15         {
    16             ThreadStart ts1 = new ThreadStart(factor);
    17             ThreadStart ts2 = new ThreadStart(series);
    18 
    19             Thread t1 = new Thread(ts1);
    20             Thread t2 = new Thread(ts2);
    21 
    22             t1.Start();
    23             t2.Start();
    24            
    25         }
    26         public static void factor()
    27         {
    28             for (int i = 1; i <= 10000; i++)
    29             {
    30                 if (10000%i==0)
    31                 {
    32                     Console.WriteLine("因子:{0}", i);
    33                 }
    34             }
    35         }
    36 
    37         public static void series()
    38         {
    39             for (int i = 1; i <= 40; i++)
    40             {
    41                 Console.WriteLine("Fibonacci[{0}]={1}", i, Fibonacci(i));
    42             }
    43         }
    44 
    45         private static  int Fibonacci(int i)
    46         {
    47             if (i>2)
    48             {
    49                 return Fibonacci(i - 1+ Fibonacci(i - 2);
    50             }
    51             else
    52             {
    53                 return 1;
    54             }
    55         }
    56     }
    57 }
    58 
  • 相关阅读:
    PAT 1142 Maximal Clique
    PAT 1076 Forwards on Weibo
    PAT 1021 Deepest Root
    PAT 1030 Travel Plan*
    diji模板
    PAT 1020 Tree Traversals
    PAT 1108 Finding Average
    PAT 1104 Sum of Number Segments
    PAT 1100 Mars Numbers
    PAT 1096 Consecutive Factors
  • 原文地址:https://www.cnblogs.com/hbhbice/p/1717295.html
Copyright © 2011-2022 走看看