日期:2014-05-18 浏览次数:20898 次
int[] xx = new int[9] { 11, 25, 3, 47, 6, 17, 38, 9, 10 }; Console.WriteLine("请输入要查询的数:"); int cx = int.Parse(Console.ReadLine()); for (int i = 0; i < xx.Length; i++) { if (xx[i] == cx) { Console.WriteLine("{0}是数组中的第{1}元素", cx, i + 1); } else if (xx[i] == xx.Length + 1) { Console.WriteLine("找不到"); } else { } } Console.ReadLine();
int[] xx = new int[9] { 11, 25, 3, 47, 6, 17, 38, 9, 10 }; Console.WriteLine("请输入要查询的数:"); int cx = int.Parse(Console.ReadLine()); for (int i = 0; i < xx.Length; i++) { if (xx[i] == cx) { Console.WriteLine("{0}是数组中的第{1}元素", cx, i + 1); break; //注意此处 } else if (xx[i] == xx.Length + 1) { Console.WriteLine("找不到"); } else { } } Console.ReadLine();