注册 登录
编程论坛 J2EE论坛

我用eclipse做的输入边长求面积为什么不能运行,谁能帮我改下

李登科 发布于 2012-03-21 19:35, 459 次点击
<%@ page language="java" contentType="text ml; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text ml; charset=GBK">
<title>Insert title here</title>
</head>
<body>
        <p>请输一条边长:</p>
        <form method="get"name="form">
        <input type="text" name="radius1">
        <p>请输一条边长:</p>
        <input type="text" name="radius2">
        <p>请输一条边长:</p>
        <input type="text" name="radius3">
        <input type="submit"name="submit"value="开始计算">
     </form>
     <%
       String a=request.getParameter("radius1");
       if(a<0)
        out.print("你输入的数字有误,请重新输入");
       else
           Double f=Double.parseDouble(a);

       String b=request.getParameter("radius2");
       if(b<0)
        out.print("你输入的数字有误,请重新输入");
       String c=request.getParameter("radius3");
       if(c<0)
        out.print("你输入的数字有误,请重新输入");
       String d=(a+b+c)/2;
       if(a+b>c&&a+c>b&&b+c>a){
           
           float s=Math.sqrt(d*(d-b)*(d-c)(d-a));
           out.print(s);
        }
       else
        out.print("你输入的三个数不能构成三角形,请重新输入");

     %>
</body>
</html>
1 回复
#2
paddys2012-03-23 17:26
String a=request.getParameter("radius1");
       if(a<0)
上面定义的字符串 下面判断是否是数字 明显的不对 要先转换成数字 再判断
1