ISC Computer Programs (Set 2)
ISC Computer Programs (Set 2)
17. Write a program in Java to accept a string terminated by a full stop (.) or a question mark (?) from the user, and
check whether the string is a snowball string or not.
[A snowball string is a sentence where each word is arranged in ascending order of their length and is also
consecutive.]
For example:-
I am the best.
He may give bonus.
18. A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit
is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The
process is repeated until the original number is reached again.
A number is said to be prime if it has only two factors 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Accept a positive number N and check whether it is a circular prime or not. The new numbers formed after the
shifting of the digits should also be displayed.
Example 2
INPUT:
N = 1193
OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME.
Example 3
INPUT:
N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME.
20. A class “Teacher” defines the related information such as name, date of birth and the date of joining while
another class “Principal” defines the different functions to display the relative information about the teachers.
The details of both the classes are given below:
Class Name : Teacher
Data members/instance variables:
String name[], dob[], doj[] : String variable to store name, date of birth and date of joining of 50 teachers.
Member functions/methods:
void getdata() : To input the values of all the data members.
void show_getdata() : To display all the data members with suitable headings.
21. A super class Detail has been defined to store the details of a customer. Define a sub class Bill to compute the
monthly telephone charge of the customer as per the chart given below:
Specify the class Detail giving details of the constructor() and void show(). Using the concept of inheritance,
specify the class Bill giving details of the constructor(), void cal() and void show().
22. Write a program in Java to store the numbers in a 4 x 4 matrix in a Double Dimensional Array. Arrange the
numbers of each row in ascending order and display the result.
Sample Input Sample Output
22 14 23 25 14 22 23 25
81 26 31 10 10 26 31 81
58 64 17 12 12 17 58 64
55 33 26 14 14 26 33 55
23. Specify a class Display_word that accepts a sentence str. Pass it to a method void Longest(String wd) to display
longest word of the sentence. The program further displays the ASCII code of each letter of the longest word.
Define the main() method to create an object and call the method Longest(String wd) to enable the task.
For example,
Sample Input: Understanding Computer Science
Sample Output: Understanding
ASCII codes are:
U : 85
n : 110
d : 100
e : 101
r : 114
s : 115
t : 116
a : 97
n : 110
d : 100
i : 105
n : 110
g : 103
24. The MOBIUS function M(N) for a natural number N is defined as:
M(N) = 1 : if N = 1
=0 : if any prime factor of N is contained in N more than once.
= (-1)p : if N is a product of p distinct prime factors
Example:
M(78) = -1 : for 78 = 2x3x13 so, M(78) = (-1)3 = -1
M(34) = 1 : for 34 = 2x17 so, M(34) = (-1)2 = 1
M(12) = 0 : for 12 = 2x2x3 so, M(12) = 0, for 2 appears two times
M(17) = -1 : for 17 = 17 so, M(17) = (-1)1 = -1, as 17 itself is a prime
Write a program to input a positive natural number N and output M(N). The program should continue till the
user wants.
Check the program for N = 666, N = 327, N = 29.
25. Given the two positive integers p and q, where p < q. Write a program to determine how many Kaprekar
numbers are there in the range between p and q (both inclusive) and output them.
The input contains two positive integers p and q. Assume p < 5000 and q < 5000. You are to output the number
of Kaprekar numbers in the specified range along with their values in the format specified below.
The following steps can be used to check whether a number is Kaprekar number or not:
(i) Find square of the number (n).
(ii) Divide the square of the number (n) in two parts in such a way that both the parts have equal number
of digits (if square number has even number of digits). In case, square of the number has odd number
of digits then divide the number in two parts such that left part may have the number of digits one less
than the right part.
(iii) Add both the parts together.
(iv) If sum obtained is equal to the original number (n), then the given number is said to be Kaprekar
number.
Example 1:
Input number = 45
Square of the number = 2025
Dividing square in two parts:
Left part = 20
Right part = 25
Sum of both the parts = 45
Hence, 45 is a Kaprekar number.
Example 2:
297
297 = 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 = 88
Sum = 209 +88 =297, i.e. equal to the number.
Sample Input:
p=1
q = 1000
Sample Output:
The Kaprekar Numbers are:
1, 9, 45, 55, 99, 297, 703, 999
Frequency of Kaprekar numbers is: 8