<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.io.*"%>
<font size="4">
<p>请输入圆的半径:
<br>
</p><form action="" method="get" name="form">
<input type="text" name="cat" value="1">
<input type="submit" value="送出" name="submit"></form>
<%!
public class Circle
{
double r;
Circle(double r)
{
this.r=r;
}
double 求面积()
{
return Math.PI*r*r;
}
double 求周长()
{
return Math.PI*2*r;
}
}
%>
<%
String str=request.getParameter("cat");
double r;
if(str!=null)
{
r=Double.parseDouble(str);
}
else{
r=1;
}
Circle circle=new Circle(r);
%>
<p>圆的面积是:
<br>
<%=circle.求面积()%>
</p></font><p><font size="4"> 圆的周长:
<br>
<%=circle.求周长()%>
</font>
</p>
运行效果: