Console.WriteLine("输入一个数组用“,”隔开:");
string str = Console.ReadLine();
string[] str2 = str.Split(",");
int[] a = new int[str2.Length];
for (int i = 0; i < str2.Length; i++)
{
a[i] = Convert.ToInt32(str2[i]);
}
Console.WriteLine("输入目标值: ");
int target = Convert.ToInt32(Console.ReadLine());
for (int k = 0; k < a.Length; k++)
{
for (int j = k+1; j < str2.Length; j++)
{
if (a[k] + a[j] == target)
{
Console.WriteLine("[" + k + "," + j + "]");
}
}
}
03-04
3744
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-03
260
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-09
7184
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交