计算1到100之间,除了能被7整除外所有整数的和

来源:互联网 发布:长春办公软件速成班 编辑:程序博客网 时间:2024/05/08 10:45

using System;
using System.Collections.Generic;
using System.Text;

namespace 循环中断计算
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            int i = 1;
            while (i <= 100)
            {
                if (i % 7 == 0)  //利用"取余"来验证当前i是否能被7整除,如果能整除余数为0;
                {
                    i++;
                    continue;  //continue之前要自增,contiue不会执行后面代码,直接跳到while中
                }
                sum = sum + i;
                i++;
            }
            Console.WriteLine("{0}", sum);
            Console.ReadKey();
        }
    }
}

原创粉丝点击