C#代码入门

JAVA学习网 2018-04-12 06:44:01

这是一个C#程序

  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Text;
  6.  
  7. namespace FindTheNumber
  8.  
  9. {
  10.   class Program
  11.   {
  12.     static void Main(string[] args)
  13.     {
  14.       int [] rg =
  15.           {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
  16.            20,21,22,23,24,25,26,27,28,29,30,31};
  17.       for (Int64 i = 1; i < Int64.MaxValue; i++)
  18.       {
  19.         int hit = 0;
  20.         int hit1 = -1;
  21.         int hit2 = -1;
  22.         for (int j = 0; (j < rg.Length) && (hit <=2) ; j++)
  23.         {
  24.           if ((i % rg[j]) != 0)
  25.           {
  26.             hit++;
  27.             if (hit == 1)
  28.             {
  29.               hit1 = j;
  30.             }
  31.             else if (hit == 2)
  32.             {
  33.               hit2 = j;
  34.             }
  35.             else
  36.               break;
  37.           }
  38.  
  39.         }
  40.         if ((hit == 2)&& (hit1+1==hit2))
  41.         {
  42.           Console.WriteLine("found {0}", i);
  43.         }
  44.       }
  45.     }
  46.   }
  47. }

 

阅读(669) 评论(0)