1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      java語(yǔ)言代碼例子 java語(yǔ)言實(shí)例

      用Java語(yǔ)言編寫一個(gè)類求圓的周長(zhǎng)

      可以通過(guò)創(chuàng)建一個(gè)圓的類完成計(jì)算圓周長(zhǎng)和面積的功能。

      創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元崇仁做網(wǎng)站,已為上家服務(wù),為崇仁各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

      假設(shè)這個(gè)圓的類名叫做Circle,因?yàn)楦鶕?jù)圓的半徑就可以求出圓的周長(zhǎng)和面積,所以可以在這個(gè)類中定義一個(gè)半徑屬性mRadius,然后定義兩個(gè)方法getLength和getArea分別實(shí)現(xiàn)計(jì)算圓周長(zhǎng)和面積的功能。

      java語(yǔ)言源代碼如下:

      public class Circle{

      //圓的半徑

      private double mRadius;

      public Circle(double mRadius){

      this.mRadius = mRadius;

      }

      //獲取圓的周長(zhǎng)

      public double getLength(){

      return 2*Math.PI*mRadius;

      }

      //獲取圓的面積

      public double getArea(){

      return Math.PI*mRadius*mRadius;

      }

      }

      //注:由于測(cè)試類只是調(diào)用Circle類的方法,功能很簡(jiǎn)單,便沒有寫測(cè)試類。

      Java語(yǔ)言編寫代碼

      代碼如下

      /**

      *?Author:?zhyx

      *?Date:2017/11/30

      *?Time:8:56

      */

      public?abstract?class?Contailner?{

      double?r;

      abstract?double?volume();

      }

      /**

      *?Author:?zhyx

      *?Date:2017/11/30

      *?Time:8:57

      */

      public?class?Cube?extends?Contailner?{

      public?Cube(double?r)?{

      this.r=r;

      }

      @Override

      double?volume()?{

      return?r*r*r;

      }

      }

      /**

      *?Author:?zhyx

      *?Date:2017/11/30

      *?Time:9:01

      */

      public?class?Sphere?extends?Contailner?{

      public?Sphere(double?r)?{

      this.r=r;

      }

      @Override

      double?volume()?{

      return?4/3*Math.PI*r*r*r;

      }

      }

      /**

      *?Author:?zhyx

      *?Date:2017/11/30

      *?Time:9:02

      */

      public?class?Tiji?{

      public?static?void?main(String[]?args)?{

      Cube?cube=new?Cube(4);

      System.out.println("立方體體積為:"+cube.volume());

      Sphere?sphere=?new?Sphere(4);

      System.out.println("球體體積為:"+sphere.volume());

      }

      }

      用java編寫一個(gè)簡(jiǎn)單例子,題目如下

      package test;

      public class Student {

      private String name;

      private String id;

      private String clazz;

      private int age;

      private String address;

      /**

      * sayHello方法

      */

      public void sayHello() {

      System.out.println("學(xué)號(hào)為" + this.id + "的同學(xué)的具體信息如下:");

      System.out.println("姓名:" + this.name);

      System.out.println("班級(jí):" + this.clazz);

      System.out.println("年齡:" + this.age);

      System.out.println("家庭住址:" + this.address);

      }

      /**

      * 測(cè)試方法

      *

      * @param args

      */

      public static void main(String[] args) {

      // 第一問

      Student student = new Student();

      student.setAddress("百度知道");

      student.setAge(1);

      student.setClazz("一班");

      student.setId("071251000");

      student.setName("lsy605604013");

      student.sayHello();

      // 第二問

      Student studentNew = new Student();

      studentNew.setAddress("搜搜知道");

      studentNew.setAge(2);

      studentNew.setClazz("二班");

      studentNew.setId("071251001");

      studentNew.setName("lady");

      if (student.getAge() studentNew.getAge())

      studentNew.sayHello();

      else if (student.getAge() studentNew.getAge())

      student.sayHello();

      else

      System.out.println("兩人一樣大");

      }

      public String getName() {

      return name;

      }

      public void setName(String name) {

      this.name = name;

      }

      public String getId() {

      return id;

      }

      public void setId(String id) {

      this.id = id;

      }

      public String getClazz() {

      return clazz;

      }

      public void setClazz(String clazz) {

      this.clazz = clazz;

      }

      public int getAge() {

      return age;

      }

      public void setAge(int age) {

      this.age = age;

      }

      public String getAddress() {

      return address;

      }

      public void setAddress(String address) {

      this.address = address;

      }

      }


      網(wǎng)頁(yè)標(biāo)題:java語(yǔ)言代碼例子 java語(yǔ)言實(shí)例
      網(wǎng)址分享:http://www.ef60e0e.cn/article/hpgdcd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        清远市| 连山| 宝鸡市| 马鞍山市| 施甸县| 昌黎县| 靖宇县| 宁武县| 壤塘县| 岫岩| 四川省| 赤壁市| 茌平县| 务川| 新余市| 平顶山市| 虎林市| 威宁| 淮滨县| 长顺县| 从化市| 扶绥县| 将乐县| 三河市| 祥云县| 淮安市| 积石山| 筠连县| 怀仁县| 莲花县| 黄冈市| 藁城市| 旺苍县| 芜湖市| 桂林市| 化州市| 钟祥市| 澄迈县| 沙洋县| 莆田市| 和政县|