为了账号安全,请及时绑定邮箱和手机立即绑定

不能算三角形的面积,请哪位大佬帮我看看(JSP代码)

不能算三角形的面积,请哪位大佬帮我看看(JSP代码)

<%@ page contentType="text/html; charset=gb2312"     pageEncoding="utf-8"%> <html><body bgcolor=cyan><font size=3> <form action="" method=post name=form>     <p>请你输入a:<input type="text" name="a" >     <br><p>请你输入b:<input type="text" name="b" >     <br><p>请你输入c:<input type="text" name="c" >     <br><input type="submit"value="提交"name=submit >     </form> <%     String str_a=request.getParameter("a");     String str_b=request.getParameter("b");     String str_c=request.getParameter("c");     double a=0,b=0,c=0; %> <%    if(str_a==null)        str_a="0";        str_b="0";        str_c="0";         %>   <%      try{             a=Double.valueOf(str_a).doubleValue();             b=Double.valueOf(str_b).doubleValue();             c=Double.valueOf(str_c).doubleValue();             if(a+b>c&&a+c>b&&b+c>a){             double p=(a+b+c)/2.0;             double mainji=Math.sqrt(p*(p-a)*(p-b)*(p-c));             out.print("<br>"+"三角形面积:"+mainji);     }     else         out.print("<br>"+"不能构成三角形");   } catch(NumberFormatException e){     out.print(e);      }     %>     </font></body></html>
查看完整描述

2 回答

?
qq_杀意隆_0

TA贡献93条经验 获得超29个赞

<%  
  if(str_a==null)  
     str_a="0";   
     str_b="0"; 
     str_c="0"; 
%>

// 这一块要改成:
<%  
  if(str_a==null)  {
     str_a="0";   
     str_b="0"; 
     str_c="0"; 
  }
%>

否则不管str_a==null是否成立,str_b和str_c都会被赋值为"0"


查看完整回答
反对 回复 2018-05-05
  • 2 回答
  • 0 关注
  • 1336 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信