题:8是幸运数字 我想知道1-n中有多少个含8的数字
解题思路:利用for循环对1-n进行int转string类型 再通过contains方法判断是否含8
class Program
{
static void Main(string[] args)
{
int n = 10000;
int count = 0;
for (int i = 1; i <= n; i++)
{
string s = i.ToString();
if (s.Contains("8"))
{
count++;
}
}
Console.WriteLine(count);
Console.ReadLine();
}
}