Q.
Write a java Program in java to input number N (1<=N<=200) and
display all the Harshad number or Niven number from the range 1 to
N.
HARSHAD NUMBER: it is the number whose sum of digit is
divisible by number.
Q. Write a program to input a number and check weather it is a
fascinating number or not.
• FASCINATING number is a number of 3 digit,such that
multiplied by 1,2,3 and than concatenated than it contains
one time all 1 to 9 digit.
Q. Write a program to enter a number from user and print that much
AUTOMORPHIC number.
• AUTOMORPHIC number is a number in which the that
number comes at the last of the square of that number
example: 5=25.
Q: Given two positive integers p and q, 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 integer p and q. Assume p<5000 and
q<5000. You are to output the numbers in the Kaprekar number in the
specified below.
The following STEPs can be used to check whether a number is
Kaprekar number or not:
1. Find the square of the number (n).
2. Divide the number in two parts in such way that both the parts have
equal Number of digits(if square has even numbers of digits).
In case, the 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.
3. Add the both parts of digits.
4. If sum obtained is equal to the original then the given number is said to
be a Kaprekar number.
Q: Enter a number and print next 20 prime number from that
number.
Q: Write a java program to enter a number and print all the composite
MAGIC Number.
• MAGIC number is the number whose sum of their digit and
if the digit is greater than 9 than again do the sum till
become 9 or smaller. If the sum is 1 than it’s a MAGIC
number.
EX: 82
=>8+2
=>10
=>1+0
=>1(MAGIC number)
Q: Write a menu driven program in java to perform the given task as
per the user’s choice :
i) To arrange a number containing three digits or more
Arrange the digits of the entered numbers in ascending order and
display result .
ii) A number is said to be a ‘Magic number’,if eventual sum of the
digits of the number is equal to 1, otherwise not .Enter a number
check whether it is number magic number or not.
Q: Write a java program to print the diganols of an array and their
sum . Matrix should be enter by the user.
Q: Write a menu driven program to make a matrix of 4X4 print a
transpose number and right triangle in java.
Q: Write a java program to enter a number and check whether it’s a
bouncy number or not.
• BOUNCY NUMBER is a number which in not there in
either ascending or descending order.
EX: 123456,654321[ bouncy]
1232145[not bouncy]
Q: A sequence of Fibonacci Strings is generated as:
S0= “a” , S1= “b” , Sn=S(n-1)+S(n-2) where ‘+’ denotes concatenation. Ex-
a,b,ba,bab,babba,babbabab…….n terms
Class Name : FiboString
Data Members :
1. x : To store First String
2. y : To store The Second String
3. z : To store concatenation of previous Two string
4. n : To store number of Terms
Member Functions :
1. FiboString() : constructor to assign a= “a”, y= “b”, z= “ab”.
2. void accept() : To accept number of terms ‘n’.
3. void generate() : to generate and print fibonacci String. The sum of
(‘+’ i.e. concatenation) first two strings is the third string.
• Ex- “a” is the first string , “b” is the second then the third will be
“ba” and fourth will be “bab” and so on.
Q: A class Encode has been defined to replace only the vowels by the
next corresponding vowel and form a new word.
i. e. A → E, E→I, I→O, O→U, U→A
and a→e,e→i,i→o,o→u,u→a
Example : Input : Institution
Output : Onstotatoun
Class Name : Encode
Data Members :
1. word : To store a word
2. length : integer to store the length of word
3. new_word : To store the encoded word
Members Functions :
1. Encode( ) : default constructor.
2. void acceptWord( ) : To accept a word.
3. void nextVowel( ) : To replace only vowels from the word
stored in ‘word’ by the next corresponding vowel and to assign
it to ‘new_word’, with the remaining alphabets unchanged.
4. void display( ) : To display original word along with the
Encrypted word.
Q: A class has been defined to check whether a sentence has words
beginning with a capital letter or not.
Class Name : Capital
Data Members :
1. sent : To store a sentence .
2. freq : Stores frequency of word beginning with a capital
letter.
Member Functions :
1. Capital( ) : Default Constructor.
2. Void input( ) : To accept a sentence.
3. boolean isCap( ) : checks and returns true if word begins with a
capital letter, otherwise returns false.
Void display( ): displays the sentence along with the frequency of
words beginning with a capital letter.
Q: Write a program to enter a line and reverse its each word in its own
position.
Sample Input : This is a class
Sample Output : sihT si a ssalc
Q: Design a class Niven to check if a given number is a Niven
number or not. [A number is said to be Niven if it is divisible by sum
of its digits.
Example: 24 = 2 + 4=6 and 24 is divisible by 6
Some of the members of the class are given below:
Class name: Niven
Data members/instance variables:
1. num: to store the number.
Methods/Member functions:
2. Niven(int nn): parameterized constructor to initialize the data
member num=nn.
3. int sum_of_digits(int i): returns the sum of digits of the
number(num), , using a recursive technique.
4. void check(): checks whether the given number is Niven or not
by invoking the function sum_of_digits() and displays the result
with an appropriate message.
Q: Design a class Perfect to check if a given number is a perfect
number or not. [A number is said to be perfect if sum of the factors of
the number excluding itself is equal to the original number]
Example: 6 = 1 + 2 + 3 (where 1, 2 and 3 are factors of 6, excluding
itself)
Some of the members of the class are given below:
Class name: Perfect
Data members/instance variables:
1. num: to store the number
Methods/Member functions:
1. Perfect (int nn): parameterized constructor to initialize the data
member num=nn
2. int sumofFactors(int n): returns the sum of the factors of the
number(num), excluding itself, using a recursive technique
3. void check(): checks whether the given number is perfect by
invoking the function sum_of_factors() and displays the result
with an appropriate message
4. Specify the class Perfect giving details of the constructor(), int
sum_of_factors(int) and void check().
5. Define a main() function to create an object and call the
functions accordingly to enable the task.
Q: Design a class ArmNum to check if a given number is an
Armstrong number or not.
[A number is said to be Armstrong if sum of its digits raised to
the power of length of the number is equal to the number]
Example:
371 = 33 + 73 + 13
1634 = 14 + 64 + 34 + 44
54748 = 55 + 45 + 75 + 45 + 85
Thus, 371, 1634 and 54748 are all examples of Armstrong numbers.
Some of the members of the class are given below:
Class name: ArmNum
Data members/instance variables:
1. n: to store the number
2. len: to store the length of the number
Methods/Member functions:
1. ArmNum (int nn): parameterized constructor to initialize the
data member n = nn.
2. int sum_pow(int i): returns the sum of each digit raised to the
power of the length of the number using recursive technique For
eg., 34 will return 32 + 42 (as the length of the number is 2).
3. void isArmstrong(): checks whether the given number is an
Armstrong number by invoking the function sum_pow () and
displays the result with an appropriate message.
• Specify the class ArmNum giving details of the constructor( ),
int sum_pow(int) and void isArmstrong( ). Define a main()
function to create an object and call the functions accordingly to
enable the task.
Q: Define a class Repeat which allows the user to add elements from
one end (rear) and remove elements from the other end (front) only.
• The following details of the class Repeat are given below:
Class name: Repeat
Data Members / Instance variables:
1. st[] : an array to hold maximum of 100 integer elements.
2. cap : stores the capacity of the array.
3. f : to point to the index of the front.
4. r : to point to the index of the rear.
Member functions:
1. Repeat(int m) : constructor to initialize the data members cap =
m, f = 0, r = 0 and to create the integer array.
2. void pushval(int v) : to add integer from rear index if possible
else display the message ("OVERFLOW").
3. int popval() : to remove and return element from the front. If
array is empty then return -9999.
4. void disp() : Displays the elements present in the list.
Q: Link is an entity which can hold a maximum of 100 integers. Link
enables the user to add elements from the rear end and remove
integers from the front end of the entity.
Class Name: Link
Data Members / Instance variables:
1. lnk[] : entity to hold the integer elements
2. max : stores the maximum capacity of the entity
3. begin : to point to the index of front end
4. end : to point to the index of rear end
Member functions / Methods:
1. Link(int mm) : constructor to initialize max = mm
2. void addlink(int v) : to add an element from the rear index if
possible otherwise display message "Out of size"
3. int dellink() : to remove and return an element from the front
index if possible otherwise display "EMPTY" and return -99
4. void display() : displays the elements of entity.
Q: Write an Inheritance Program for the given details:
Number of Calls : Rate
1–100 : Only Rental Charge.
101–200 : 60 paise per call + rental charge.
201–300 : 80 paise per call + rental charge.
300 above : ₹1 per call + rental charge.
Class name: Detail
Data members:
1. name : to store name.
1. address : to store address.
2. telno : to store telephone number.
3. rent : to store rental charge.
Member functions:
1. Detail() : Parameterized constructor.
2. void show() : to display elements.
Class name: Bill
Data Members:
1. n : to store number of calls.
2. amt : to store amount.
Member functions:
1. Bill() : Parameterized constructor.
2. void cal() : to calculate charge.
3. void show() : to display all elements.
Q: WordPile is an entity which can hold maximum 20 characters. The
restriction is that a character can be added or removed from one end only.
• Some of the members of class are given below:
Class name: WordPile
Data Members / Instance variables:
1. ch[] : character array to hold the character elements
2. capacity : integer variable to store the maximum capacity
3. top : to point to the index of the topmost element
Methods / Member functions:
1. WordPile(int cap) : constructor to initialize the data members
capacity, top etc. and create the WordPile
2. void pushChar(char v) : adds the character to the top of WordPile if
possible; otherwise outputs a message "WordPile is full"
3. char popChar() : returns the deleted character from the top of the
WordPile if possible, otherwise returns ''.
• Specify the class WordPile giving details of constructor, void
pushChar(char v) and char popChar().
Q: Register is an entity which can hold a maximum of 100 names.
The register enables the user to add and remove names from top most
end only.
Define a class Register with the following details:
Class name: Register
Data Members:
1. stud[] → To store name in the string array.
2. cap → Integer variable to store the maximum capacity.
3. top → To point to the index of the top end.
Methods:
Register(int max) → Constructor to initialize data member, cap =
max, top = 0, and create string array.
void push(String n) → To add names in the register at top location if
possible, otherwise print "OVERFLOW".
String pop() → Removes and returns the names from the topmost
location of the register, if any. Else returns "$$".
void display() → Displays all the names in the register.