答:
private static int[] UnionLottoArray()
{
//获取数据
do
{
Console.WriteLine('\n' + "请输入7注彩票数:(格式:xx,xx,xx,xx)");
string lotteryNumber = Console.ReadLine();
string[] segmentation = lotteryNumber.Split(',');
int[] unionLotto = Array.ConvertAll(segmentation, int.Parse);
//1.是否输入了7个数
//2.数字是否都是大于1小于33
//3.是否有重复值
if (unionLotto.Length != 7)
{
Console.WriteLine("输入有误,请重新输入1");
continue;
}
for (int i = 0; i < unionLotto.Length; i++)
{
if (unionLotto[i] < 1 || unionLotto[i] > 33)
{
Console.WriteLine("输入有误,请重新输入2");
unionLotto = null;
break;
}
}
if (unionLotto == null) continue;
for (int i = 0; i < unionLotto.Length - 1; i++)
{
for (int j = i + 1; j < unionLotto.Length; j++)
{
if (unionLotto[i] == unionLotto[j])
{
Console.WriteLine("有重复值,请重新输入");
unionLotto = null;
break;
}
}
if (unionLotto == null) break;
}
if (unionLotto == null) continue;
else
{
Console.WriteLine("这回肯定行");
return unionLotto;
}
} while (true);
}