本人要求奇数和偶数!哪里有问题求指导!
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 规律数 { class Program { public int[] GetData() { int[] iArray = new int[30]; iArray[0] = 1; iArray[1] = 1; int iOddNum, IevenNum; for (int i = 2; i < 30; i++) { iArray[i] = iArray[i - 1] + iArray[i - 2]; Console.WriteLine(iArray[i]); } return iArray; GetOddEven(ref iOddNum, ref IevenNum); Console.WriteLine("奇数的个数是:{0},偶数的个数是:{1}", iOddNum, IevenNum); Console.ReadLine(); } public void GetOddEven(ref int iOddNum, ref int IevenNum) { int[] iArry = GetData(); foreach (int item in iArry) { if (item % 2 == 0) { iOddNum++; } else { IevenNum++; } } } static void Main(string[] args) { Program a = new Program(); a.GetData(); Console.ReadLine(); } } }
解决方案
20
那就a= new Program();
a.GetOddEven(xxxx);