求关于vb的数组输出问题,求代码?
展开全部
是vb.net吗?
Module
test
Public
Sub
Main()
Dim
a(9)
As
Integer
Console.Write("输入10个数字:")
Dim
line
As
String
=
Console.ReadLine()
Dim
x()
As
String
=
(line.Split("
"))
If
x.Length
<>
10
Then
Console.WriteLine("输入数量不正确.")
Return
End
If
For
i
=
0
To
9
a(i)
=
CInt(x(i))
Next
Dim
odd,
even,
oddsum,
evenpro
As
Integer
evenpro
=
1
For
Each
i
In
a
If
i
And
1
Then
odd
=
odd
+
1
oddsum
+=
i
Else
even
=
even
+
1
evenpro
*=
i
End
If
Next
Array.Sort(a)
Array.Reverse(a)
Console.Write("由大到小输出:")
For
Each
i
In
a
Console.Write("{0}
",
i)
Next
Console.WriteLine()
Console.Write("奇数个数:{0}"
+
ControlChars.Tab,
odd)
Console.WriteLine("奇数和:{0}",
oddsum)
Console.Write("偶数个数:{0}"
+
ControlChars.Tab,
even)
Console.WriteLine("偶数积:{0}",
evenpro)
End
Sub
End
Module
Module
test
Public
Sub
Main()
Dim
a(9)
As
Integer
Console.Write("输入10个数字:")
Dim
line
As
String
=
Console.ReadLine()
Dim
x()
As
String
=
(line.Split("
"))
If
x.Length
<>
10
Then
Console.WriteLine("输入数量不正确.")
Return
End
If
For
i
=
0
To
9
a(i)
=
CInt(x(i))
Next
Dim
odd,
even,
oddsum,
evenpro
As
Integer
evenpro
=
1
For
Each
i
In
a
If
i
And
1
Then
odd
=
odd
+
1
oddsum
+=
i
Else
even
=
even
+
1
evenpro
*=
i
End
If
Next
Array.Sort(a)
Array.Reverse(a)
Console.Write("由大到小输出:")
For
Each
i
In
a
Console.Write("{0}
",
i)
Next
Console.WriteLine()
Console.Write("奇数个数:{0}"
+
ControlChars.Tab,
odd)
Console.WriteLine("奇数和:{0}",
oddsum)
Console.Write("偶数个数:{0}"
+
ControlChars.Tab,
even)
Console.WriteLine("偶数积:{0}",
evenpro)
End
Sub
End
Module
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询