Page 191 - computer science (868) class 11
P. 191
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.
14. Assume that new tax rates and deduction rules have been implemented as shown below:
Annual income (in `) Tax Rates for Females Tax Rates for Males
up to 100000 nil nil
100000 to 200000 10% 12%
200000 to 300000 20% 22%
300000 to 500000 30% 33%
Write a Java program to input employee id, annual income and gender (F for female and M for male). Compute the income tax
using the above criteria and print employee id, gender and tax amount.
15. Write a program to display the following pattern using switch case.
i. 1 ii. 1 2 3 4 5
3 1 6 7 8 9
5 3 1 10 11 12
7 5 3 1 13 14
15
189
Statements and Scope 189

