一个数组,如:{100,200,300,400}
输入一个数x,求数组中,小于x的最大值y;
即,当x=350时,y=300
输入一个数x,求数组中,小于x的最大值y;
即,当x=350时,y=300
解决方案 »
- c#模拟点击按钮提交表单问题
- 紧急 求一小段代码!!!关于tick的
- class1 ca = new class1(); 和 class 1 ca; ca = new class1();有什么区别
- 用C#写的Winforms程序,如何生成单独的EXE文件
- datawindow.net 中的打印预览如何实现?
- 程序集的问题!!
- 如何实现.NET中的多窗口显示功能?
- C#方法调用的问题!
- 在设计表单时,在button的text属性处输入内容,有时由于字符过长,而button的默认宽度过小,时常需手工调整button宽度,请问有无一个类似a
- 菜鸟问题:在线等候!我安装完.net不能进行单步调试!
- 还原.BAK数据文件
- 调用exe程序,不显示界面
public static int maxCaculate(int[] array, int x)
{
int[] temp = new int[array.Length + 1];
Array.Copy(array, temp, array.Length);
temp[temp.Length - 1] = x;
Array.Sort(temp);
return temp[Array.IndexOf(temp, x) - 1];
}
public void Find(int[] array, int x)
{
int temp = x;
foreach (int i in array)
{
if (i >= x)
continue;
if (temp == x || temp < i)
temp = i;
}
//未找到就输出x本身
System.Console.WriteLine(temp);
}
{
int[] temp = new int[array.Length + 1];
Array.Copy(array, temp, array.Length);
temp[temp.Length - 1] = x;
Array.Sort(temp);
if (Array.IndexOf(temp, x) != 0)
return temp[Array.IndexOf(temp, x) - 1];
else
return x;
}