Page 125 - Cs_withBlue_J_C11_Flipbook
P. 125

14             System.out.print("Enter radius of a sphere in cm  : ");
                   15             r=sc.nextDouble();

                   16             vs=4.0/3.0 * 3.14 * r * r * r;
                   17             System.out.println("Volume of a sphere : "+vs + " cu cm ");

                   18             System.out.println("-----------------------");
                   19             System.out.print("Enter length of a cuboid in cm  : ");

                   20             l=sc.nextInt();
                   21             System.out.print("Enter breadth of a cuboid in cm : ");
                   22             b=sc.nextInt();

                   23             System.out.print("Enter height of a cuboid in cm  : ");

                   24             h=sc.nextInt();
                   25             vcd=l * b * h;
                   26             System.out.println("Volume of a cuboid : "+vcd + " cu cm ");

                   27             System.out.println("-----------------------");
                   28         }

                   29     }
                 The output of the preceding program is as follows:






















                   Program 3     To input two integer numbers and print their sum.

                   1      import java.util.*;

                   2      class try_catch
                   3      {
                   4          public static void main()

                   5          {

                   6              Scanner sc = new Scanner(System.in);
                   7              int a,b,s;
                   8              try



                                                                                                                       123
                                                                                                             Objects   123
   120   121   122   123   124   125   126   127   128   129   130