0-100整数字包含几个9?
private void button1_Click(object sender, EventArgs e)
{
int j = 0;
string sum = "";
for (int i = 0; i <= 100;i++ )
{
if (i.ToString().IndexOf('9') > -1)
{
j = j + 1;
}
sum = sum + i.ToString();
}
MessageBox.Show(j.ToString());
MessageBox.Show(sum.ToString());
}
输出结果:
其中99包含两个9.
共20个9.