天高任鸟飞,海阔凭鱼跃
分类:
2010-06-19 19:46:34
基于WEB服务的在线计算器
-----------------------------------
方法一:
--------------------------------
try
{
double a1 = Convert.ToDouble(TextBox1.Text);
double a2 = Convert.ToDouble(TextBox2.Text);
if (DropDownList1.SelectedValue == "+")
{
Label1.Text = Convert.ToString(a1 + a2);
}
else if (DropDownList1.SelectedValue == "-")
{
Label1.Text = Convert.ToString(a1 - a2);
}
else if (DropDownList1.SelectedValue == "*")
{
Label1.Text = Convert.ToString(a1 * a2);
}
else if (DropDownList1.SelectedValue == "/")
{
if (a2 == 0)
{
Label1.Text = "被除数不能为零!";
}
else
{
Label1.Text = Convert.ToString(a1 / a2);
}
}
}
catch
{
Label1.Text = "请在文本框内输入数字!";
}
方法二:
------------------------
try
{
double a1 = Convert.ToDouble(TextBox1.Text);
double a2 = Convert.ToDouble(TextBox2.Text);
switch (DropDownList1.SelectedValue)
{
case "+":
Label1.Text = Convert.ToString(a1 + a2);
break;
case "-":
Label1.Text = Convert.ToString(a1 - a2);
break;
case "*":
Label1.Text = Convert.ToString(a1 * a2);
break;
case "/":
Label1.Text = Convert.ToString(a1 / a2);
break;
}
}
catch
{
Label1.Text = "请您在文本框内输入数字!";
}
方法三:
-----------------------
try
{
double a1 = Convert.ToDouble(TextBox1.Text);
double a2 = Convert.ToDouble(TextBox2.Text);
switch (DropDownList1.SelectedValue)
{
case "+":
TextBox3.Text = Convert.ToString(a1+a2);
break;
case "-":
TextBox3.Text = Convert.ToString(a1 - a2);
break;
case "*":
TextBox3.Text = Convert.ToString(a1 * a2);
break;
case "/":
TextBox3.Text = Convert.ToString(a1 / a2);
break;
}
}
catch
{
Label1.Text = "请您在文本框内输入数字!";
}
---------------------------------------------------------------
九九乘法口诀表
-------------------------
方法:
九九乘法口诀表(数字型)
------------------------
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
Label1.Text=Label1.Text+i.ToString()+"x"+j.ToString()+"="+Convert.ToString(i*j)+" "+" ";
} Label1.Text += "
";
}
-----------------------------