发一个逻辑问题 挺简单 但是我想了一天没有想出来
有一组一维数组 1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
1 1 1 1 1 1 2 2 2
1到6的值为“1” 7到9的值为2
for(int i = 1 ; i < 10 ; i++)
{
if( 数组[i] !=1 )
{
listview.items.add(i);
把值为1的数组列出来
得到 1 2 3 4 5 6;
}
}
以上逻辑如何写啊?忘老鸟指教
程序代码:using System;
using System.Collections.Generic;
using System.Text;
namespace ArrayTest
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 1, 1, 1, 1, 1, 2, 2, 2 };
for (int i = 0; i < arr.Length;i++ )
{
if (arr[i] == 1) Console.WriteLine((i+1));
}
Console.ReadKey();
}
}
}