<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Java 程序:使用方法重載查找幾何圖形的面積 > 原文: [https://beginnersbook.com/2017/09/java-program-to-find-area-of-geometric-figures-using-method-overloading/](https://beginnersbook.com/2017/09/java-program-to-find-area-of-geometric-figures-using-method-overloading/) 該程序使用方法重載找到正方形,矩形和圓形的面積。在這個程序中,我們有三個同名的方法`area()`,這意味著我們正在重載`area()`方法。通過面積方法的三種不同實現,我們計算方形,矩形和圓形的面積。 要理解這個程序,你應該具備以下[核心 Java](https://beginnersbook.com/java-tutorial-for-beginners-with-examples/) 主題的知識: [Java 中的方法重載](https://beginnersbook.com/2013/05/method-overloading/) ## 示例:使用方法重載編程以查找方形,矩形和圓的面積 ```java class JavaExample { void calculateArea(float x) { System.out.println("Area of the square: "+x*x+" sq units"); } void calculateArea(float x, float y) { System.out.println("Area of the rectangle: "+x*y+" sq units"); } void calculateArea(double r) { double area = 3.14*r*r; System.out.println("Area of the circle: "+area+" sq units"); } public static void main(String args[]){ JavaExample obj = new JavaExample(); /* This statement will call the first area() method * because we are passing only one argument with * the "f" suffix. f is used to denote the float numbers * */ obj.calculateArea(6.1f); /* This will call the second method because we are passing * two arguments and only second method has two arguments */ obj.calculateArea(10,22); /* This will call the second method because we have not suffixed * the value with "f" when we do not suffix a float value with f * then it is considered as type double. */ obj.calculateArea(6.1); } } ``` **輸出:** ```java Area of the square: 37.21 sq units Area of the rectangle: 220.0 sq units Area of the circle: 116.8394 sq units ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看