这是一道很简单很简单的题目,发现不管学习哪种语言,只要掌握了它的语法和格式就行了,和设计程序的思维方法没多大关系。。
题目 :找出数组中最大的一个值对应的下标
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace searchmax { class fmax { public static void find(int[] AA)//非静态的字段、方法或属性“searchmax.fmax.find(int[])”要求对象引用
{ int i,k,max; k = 0; max = AA[0]; for (i = 0; i < 5; i++) { if (max < AA[i]) { k = i; max = AA[i]; } } Console.WriteLine("最大元素下标为{0}",k); } static void Main(string[] args) { int [] AA = {5,15,36,15,35}; find(AA);
} } }
|
这里出现个问题,为什么不给k赋初值,程序就会报错?是和它存在在静态方法中有关么???
阅读(264) | 评论(0) | 转发(0) |