计算三角形面积的页面

GetArea.tag

<%@ tag import="java.util.*" %>
<%@ attribute name="sideA" required="true" %>
<%@ attribute name="sideB" required="true" %>
<%@ attribute name="sideC" required="true" %>
<%@ variable name-given="area" variable-class="java.lang.Double"  scope="AT_END" %>
<%
double a=Double.parseDouble(sideA);
double b=Double.parseDouble(sideB);
double c=Double.parseDouble(sideC);
if(a+b>c&&a+c>b&&b+c>a){
double p=(a+b+c)/2.0;
double area0=Math.sqrt(p*(p-a)*(p-b)*(p-c));
jspContext.setAttribute("area",new Double(area0));
}
else{
jspContext.setAttribute("area",new Double(-1.0));
}
%>

one.jsp

<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.text.*" %>
<%@ taglib tagdir="/WEB-INF/tags/ch3" prefix="computer" %>
<HTML><BODY BGCOLOR=#F0F8FF>
<TITLE>one</TITLE>
<computer:GetArea sideA="3.1" sideB="4.2" sideC="5.3"/>
<%
NumberFormat f=NumberFormat.getInstance();
f.setMaximumFractionDigits(3);
if(area!=-1){
double s=area.doubleValue();
String str=f.format(s);
out.print("面积是:"+str);
}
else out.print("不能构成三角形");
%>
</BODY>
</HTML>

two.jsp

<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.text.*" %>
<%@ taglib tagdir="/WEB-INF/tags/ch3" prefix="computer" %>
<HTML><BODY BGCOLOR=#F0F8FF>
<TITLE>one</TITLE>
<computer:GetArea sideA="3.1" sideB="4.2" sideC="5.3"/>
<%
NumberFormat f=NumberFormat.getInstance();
f.setMaximumFractionDigits(6);
if(area!=-1){
double s=area.doubleValue();
String str=f.format(s);
out.print("面积是:"+str);
}
else out.print("不能构成三角形");
%>
</BODY>
</HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值