Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 2 decades ago

且讓我問一題超容易的JAVA吧

這提我想大家一定沒問題

幫個忙囉

期末將至

題目2

試建立一個名為csphere的類別,其資料成員及型態如下

double pi = 3.14; (4/3 * PI * r ^ 3)

double radius;

試在csphere 類別裡定義成員函數volume( ),用來計算並傳回球的體積

試在main( ) method裡建立一個csphere 類別型態的物件sph

將sph物的radius之值設為2

印出sph物件的radius與球體積之值

----------

隨便回答也行喔

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    public class csphere

    {

    double pi = 3.14;

    double radius;

    public static void main(String args[])

    {

    csphere sph = new csphere();

    sph.radius=2;

    System.out.println("radius="+sph.radius);

    System.out.println("球體積之值="+sph.volume(sph.pi,sph.radius));

    }

    public double volume(double PI ,double r)

    {

    return 4/3*PI*r*r*r;

    }

    }

    你要的是這樣子嗎

Still have questions? Get your answers by asking now.