Page 124 - Cs_withBlue_J_C11_Flipbook
P. 124

9              p=sc.nextDouble();
                10              System.out.print("Enter the rate: ");

                11              r=sc.nextDouble();
                12              System.out.print("Enter the number of years: ");

                13              t=sc.nextDouble();
                14              si=(p*r*t)/100.0;

                15              System.out.println("Simple Interest: "+si);
                16          }
                17      }


              The output of the preceding program is as follows:















                Program 2      To find the volume of a cube, a sphere and a cuboid by accepting the required values from the
                               user using Scanner class.
                               Hint:
                               Volume of a cube (vc) = s * s * s          where s is a side of the cube
                               Volume of a sphere (vs) = 4 / 3 * π * r * r * r      where π = 3.14 or 22 / 7 and r is a radius of sphere
                               Volume of a cuboid (vcd) = l * b * h

                 1      import java.util.*;

                 2      class scanner
                 3      {

                 4          public static void main()
                 5          {

                 6              Scanner sc = new Scanner(System.in);
                 7              int s,l,b,h,vc,vcd;

                 8              double r,vs;
                 9              System.out.print("Enter side of a cube in cm  : ");

                10              s=sc.nextInt();
                11              vc=s*s*s;
                12              System.out.println("Volume of a cube : "+vc + " cu cm ");

                13              System.out.println("-----------------------");




                122122  Touchpad Computer Science-XI
   119   120   121   122   123   124   125   126   127   128   129