Page 241 - ComputerScience_Class_11
P. 241

10.  Write a Java program to print the following using a switch case.
                        a.  *****         b.  *
                           ****              * *
                           ***               * * *
                           ***               * * * *
                            **               * * * * *
                             *               * * * *
                                             * * *
                                             * *
                                             *
                    11.  Write a menu-driven program in Java to input a number and check whether it is a Kaprekar number or a Fascinating number.
                        •   A number is called Capricorn or Kaprekar number whose square is divided into two parts in any conditions and parts are added,
                        the sum of the parts is equal to the number itself.
                          Example: 45
                              2
                          45 =  45  = 2025
                          Combinations of the parts of 2025 and their sum:
                          202 + 5 = 207 (not 45)
                          20 + 25 = 45
                          2 + 025 = 27 (not 45)
                          Here, we can see that one combination is equal to the number itself. So, 45 is a Capricorn or Kaprekar number.
                        •   A number is a Fascinating number when the number is multiplied by 2 and 3 and is concatenated with both the products, then
                        all the digits from 1 to 9 are present exactly once, regardless of the number of zeroes.
                          Example:
                          Consider the number 192
                          192 x 1 = 192
                          192 x 2 = 384
                          192 x 3 = 576
                          Concatenating the results: 192 384 576
                          Here, we can see that '192384576' consists of all digits from 1 to 9 exactly once. So, 192 is a Fascinating number.
                    12.  Write a Java program to compute the railway fare depending on the given criteria as follows:

                           Age (in  years)    Distance (in kms)  Fare (in rupees)
                       Below 10             Below 10                  5
                                            Between 10 and 50         20
                                            Above 50                  50
                       Between 10 and 60    Below 10                  10
                                            Between 10 and 50         40
                                            Above 50                  80
                       Above 60             Below 10                  4
                                            Between 10 and 50         15
                                            Above 50                  35
                    13.  The volume of solids, viz. cuboid, cylinder and cone can be calculated by the following formula:
                        Volume of a cuboid (v = l*b*h)      - if choice is 1
                                             2
                        Volume of a cylinder (v = π*r *h)      - if choice is 2
                                               2
                        Volume of a cone (v = (1/3)*π*r *h)     - if choice is 3
                        Using a switch case statement, write a Java program to find the volume of different solids by taking suitable variables and
                       data types.






                                                                                              Statements and Scope  239
   236   237   238   239   240   241   242   243   244   245   246