码迷,mamicode.com
首页 > 其他好文 > 详细

foreach & Random

时间:2014-11-16 21:19:27      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   sp   for   div   on   log   

using System;
public class ForEachTest
{
    public static void Main()
    {
        int odd=0;
        int eve=0;
        int length=100;
        int[] arr=new int[length];
        Random r = new Random();
        for(int i=0;i<length;i++)  //随机数赋值
        {
            arr[i]= r.Next();
        }    
        foreach(int tem in arr)  //foreach 举例
        {
            if(tem%2==0)
                eve++;
            else
                odd++;
        }
        Console.WriteLine("奇数"+odd+"");
        Console.WriteLine("偶数"+eve+"");
    }    
}

 

foreach & Random

标签:style   blog   color   ar   sp   for   div   on   log   

原文地址:http://www.cnblogs.com/quke123/p/4101809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!