using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 打印1_100以内不是7的倍数或含有7的数
{
class Program
{
static void Main(string[] args)
{
#region //第一种方法
for (int i = 1; i < 101; i++)
{
//这里直接使用i值会使程序进入一个死循环
int number = i;
bool isContaint7 = false;
while (number / 10 != 0)
{
//记录的是余数
int temp = i % 10;
if (temp == 7)
{
//含有7
isContaint7 = true;
break;
}
number /= 10;
}
if (number == 7 || isContaint7 == true)
{
//含有7
isContaint7 = true;
}
else
{
isContaint7 = false;
}
if (i % 7 == 0 || isContaint7 == true)
{
continue;
}
Console.WriteLine(i);
}
#endregion
////第二种方法
//for (int i = 1; i < 100; i++)
//{
// if (i%7==0 || i.ToString().Contains("7"))
// {
// continue;
// }
// Console.WriteLine(i);
//}
}
}
}
打印1_100以内不是7的倍数或含有7的数
最新推荐文章于 2023-01-03 19:09:12 发布