【jsp 練習】 給定三角形三邊判斷是否能組成三角形及計算面積

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   java   for   

Test.java

package package1;public class Test {    double side1 = -1 , side2 = -1 , side3 = -1 , area = -1;    boolean triangle;        public double getSide1() {        return side1;    }    public void setSide1(double side1) {        this.side1 = side1;    }    public double getSide2() {        return side2;    }    public void setSide2(double side2) {        this.side2 = side2;    }    public double getSide3() {        return side3;    }    public void setSide3(double side3) {        this.side3 = side3;    }    public double getArea() {        double p = (side1 + side2 + side3)/2.0;        if(triangle) area = Math.sqrt( p * (p - side1) * (p - side2) * (p - side3) );        return area;            }    public void setArea(double area) {        this.area = area;    }    public boolean isTriangle() {        if(side1<side2+side3 && side2<side1+side3 && side3<side1+side2)            triangle=true;        else triangle=false;        return triangle;    }    public void setTriangle(boolean triangle) {        this.triangle = triangle;    }   }

 

 

 

 

triangle.jsp

<%@page contentType="text/html;charset=gb2312" pageEncoding="gb2312" %><%@page import="package1.Test" %><jsp:useBean id="tri" class="package1.Test" scope="page" /><html>    <head></head>    <body>        <form action="" method="post">            a:<input type="text" name="side1" value="0" />            b:<input type="text" name="side2" value="0" />            c:<input type="text" name="side3" value="0" />            <input type="submit" value="submit" />        </form>                <jsp:setProperty name="tri" property="*" />                三角形的三邊是:        邊a :<jsp:getProperty name="tri" property="side1" />        邊b :<jsp:getProperty name="tri" property="side2" />        邊c :<jsp:getProperty name="tri" property="side3" />        <br />        是否能組成三角形:        <jsp:getProperty name="tri" property="triangle" />                <!-- 如果不先判斷是否是triangle的話,servlet類中獲得面積時的triangle判斷恒為假,area輸出結果值始終為-1 -->                面積是:        <jsp:getProperty name="tri" property="area" />    </body></html>

 

【jsp 練習】 給定三角形三邊判斷是否能組成三角形及計算面積

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.