求大神帮帮我解决这道题,谢谢!
VB程序设计,用VB做出效果就可以,需要代码,谢谢!
namespace Ini_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static int[] randomArr = null;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
label6.Text = "生成中...";
if(randomArr==null){
randomArr=new int[500];
}
for (int i = 0; i < 500;i++ )
{
Random rd = new Random();
int random=rd.Next(0,500);
randomArr[i] = random;
textBox1.Text =textBox1.Text + random.ToString()+" ";
Delay(10);//延迟是因为生成随机数频率太快导致生成随机数大都相同了
}
label6.Text = "生成完成";
}
private void button2_Click(object sender, EventArgs e)
{
if(randomArr==null){
label6.Text="请先生成";
return;
}
int sevenFlag = 0;
int zeroFlag = 0;
for (int i = 0; i < randomArr.Length;i++ )
{
if(randomArr[i]%7==0){
sevenFlag++;
}
if(randomArr[i]==0){
zeroFlag++;
}
}
if(zeroFlag==0){
MessageBox.Show("没有0");
}
if(sevenFlag==0){
MessageBox.Show("没有整除7的整数");
}
label5.Text = sevenFlag.ToString();
label4.Text = zeroFlag.ToString();
}
public virtual bool Delay(int delayTime)
{
DateTime now = DateTime.Now;
int s;
do
{
TimeSpan spand = DateTime.Now - now;
s = spand.Milliseconds;
Application.DoEvents();
}
while (s < delayTime);
return true;
}
}
}