龙空技术网

jsp实现-圆形和梯形面积的计算

编程有你 107

前言:

当前大家对“js圆形”大体比较讲究,你们都需要剖析一些“js圆形”的相关文章。那么小编在网摘上汇集了一些关于“js圆形””的相关资讯,希望看官们能喜欢,小伙伴们快快来了解一下吧!

首先编写:main.jsp:用来实现用户界面的输入。

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<head></head>

<body bgcolor="yellow">

<form action="circle.jsp" method=get>//发送到circle.jsp

圆形半径:<input type="text" value="" name="t1"></br>

<input type="submit" value="提交">

</form>

<form action="ladder.jsp" method=get>//发送到ladder.jsp

梯形上底:<input type="text" value="" name="top"></br>

梯形下底:<input type="text" value="" name="bottom"></br>

&nbsp;&nbsp;&nbsp;梯形高:<input type="text" value="" name="height"></br>

<input type="submit" value="提交">

</form>

</body>

</html>

在编写circle.jsp://用来计算圆形面积

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<head></head>

<body bgcolor="yellow">

<%!

public double getArea(double r){

double area=3.14*r*r;

return area;

}

%>

<%

String c1=request.getParameter("t1");//获取用户输入的半径

double c2=Double.parseDouble(c1);//转成double

%>

</br>半径为<%=c2%>的圆形的面积:<%=getArea(c2)%>//调用计算面积的方法

</body>

</html>

在编写:ladder.jsp:用来计算梯形的面积

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<head></head>

<body bgcolor="yellow">

<%!

public double getArea(double t,double b,double h){

double area=(t+b)*h/2;

return area;

}

%>

<%

String top=request.getParameter("top");

String bottom=request.getParameter("bottom");

String height=request.getParameter("height");

double t=Double.parseDouble(top);

double b=Double.parseDouble(bottom);

double h=Double.parseDouble(height);

%>

</br>上底为:<%=t%></br>

下底为:<%=b%></br>

高为:<%=h%></br>

梯形的面积:<%=getArea(t,b,h)%>

</body>

</html>

效果演示:

标签: #js圆形 #jsp输入一个半径求圆的面积 #编程求园的面积