Page 244 - CA_Blue( J )_Class10
P. 244

Program 6     To compute the volume of a sphere and a cuboid using the concept of function overloading
                              Volume of a cube(vc) = s * s * s
                              Volume of a sphere(vs) = 4/3*π*r 3
                              Volume of a cuboid(vcd)=l*b*h


                 1  import java.util.*;
                 2  class overload_shape{

                 3      void volume(int s){
                 4          int vc=s*s*s;

                 5          System.out.println("Volume of cube "+vc);

                 6      }
                 7      void volume(double r){
                 8          double vs=4.0/3.0*22.0/7.0*r*r;;

                 9          System.out.println("Volume of sphere "+vs);

                10      }
                11      void volume(int l, int b, int h){
                12          int vcd=l*b*h;

                13          System.out.println("Volume of cuboid "+vcd);
                14      }

                15      public static void main(){
                16          overload_shape obj = new overload_shape();

                17          obj.volume(5);
                18          obj.volume(4.5);

                19          obj.volume(4,6,8);
                20      }

                21  }

                              To print the sum of the following:
                Program 7     a. s=1/2+3/4+5/6+…… n terms by using function series(double)
                              b. s=x/1+x/3+x/5+x/7+……+x/n by using function series (double, double)
                              Using user's choice.
                 1  import java.util.*;

                 2  class overload_series
                 3  {

                 4      double series(double n)
                 5      {





                242242  Touchpad Computer Applications-X
   239   240   241   242   243   244   245   246   247   248   249