using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1210_遍历数组
{
class Program
{
static void Main(string[] args)
{
//在C#中,可以使用foreach语句来遍历数组的元素:
// C#遍历数组-www.baike369.com
int odd = 0; // 奇数
int eve = 0; // 偶数
int[] array = new int[100];
for (int i = 0; i < array.Length; i++)
{
array[i] = i * 5;
}
foreach (int j in array)
{
if (j % 2 == 0)
eve++;
else
odd++;
}
Console.WriteLine("奇数有" + odd + "个");
Console.WriteLine("偶数有" + eve + "个");
Console.ReadLine();
}
}
}
如上描述如有不懂,或想学习更多技术知识,可以扫码关注麒琳技术栈公众号,欢迎在线咨询


1104

被折叠的 条评论
为什么被折叠?



