String.IndexOf 方法
int sum = 0;
var Numbers = new List<int> { };
int j;
for (int i = 1; i <= 100; i++)
{
j = i.ToString().Length;
if (((i % 7) == 0) || (i.ToString().IndexOf("7", 0, j) != -1))
{
sum = sum + i;
Numbers.Add(i);
}
}
Console.WriteLine("和为" + sum);
foreach (var item in Numbers)
{
Console.WriteLine(item);
}
Console.ReadLine();
double sum = 100000;
int fre = 0;
while (sum > 5000)
{
if (sum > 50000)
{
sum = sum * 0.95;
fre = fre + 1;
}
else if (sum <= 50000)
{
sum = sum - 5000;
fre = fre + 1;
}
}
Console.WriteLine($"最多经过{fre}次路口,余额为{sum.ToString("F1")}");
Console.ReadLine();
var fibonacciNumbers = new List<int> { 1, 1 };
for (int i = 2; i <= 36; i++)
{
int previous = fibonacciNumbers[i - 1];
int preivous2 = fibonacciNumbers[i - 2];
fibonacciNumbers.Add(preivous2 + previous);
Console.WriteLine($"斐波拉契数列第{i+1}个数是{fibonacciNumbers[i]}");
}
var list = new List<int> { };
int count;
for (int i = 100; i < 1000; i++)
{
int j = i % 10;
int k = (i / 10) % 10;
int m = i / 100;
if (Math.Pow(j,3)+Math.Pow(k,3)+Math.Pow(m,3)==i)
{
list.Add(i);
}
}
int a=1;
for (int i = 1; i < 7; i++)
{
a = Fun(a);
Console.WriteLine(a.ToString());
}
Console.ReadKey();
}
static int Fun(int n)
{
return (n + 1) * 2;
}