Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Answer the following questions

1. What is class?why is class called an object factory?


2. What is object?
3. What is Encapsulation?
4. What is inheritance?
5. What is Polymorphism?
6. What is Abstraction ?
7. Write difference between while and do-while loop?
8. What are primitive and reference data type?

Programs

1. Write a Program in Java to input a number and check whether it is a Pronic Number or A
Pronic number is a number which is the product of two consecutive integers, that is, n (n
+ 1). The first few Pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210,

240, 272, 306, 342, 380, 420, 462 ... etc.

2. A happy number is a number in which the eventual sum of the square of the digits of the
number is equal to 1.

Example:28 = 22 + 8 2 = 4 + 64 = 68 68= 6 2 + 82 = 36 + 64 = 100

100= 1 2 + 0 2 + 0 2= 1 + 0 + 0 = 1 Hence, 28 is a happy number.

Design a class happy to check if a given number is a happy number.

3. Write a Java program to check if a number entered is a Neon Number or not, in JAVA. A
number is said to be a Neon Number if the sum of digits of the square of the number is
equal to the number itself.

Example- 9 is a Neon Number. 9*9=81 and 8+1=9.Hence it is a Neon Number.

4. A number is a Spy number, if sum and product of all digits are equal.

Example: Number 123 is a Spy number, sum of its digits is 6 (1+2+3 =6) and product of its
digits is 6 (1x2x3 = 6), sum and product are same, thus, 123 is a spy number.

Write a Java program to check whether a Given Number is spy no. Or not.

1
5. A number is called an automorphic number if and only if the square of the given number
ends with the same number itself. For example, 25, 76 are automorphic numbers
because their square is 625 and 5776, respectively and the last two digits of the square
represent the number itself.

6. A Dudeney number is a positive integer that is a perfect cube such that the sum of its
digits is equal to the cube root of the number. Write a program to input a number and
check and print whether it is a Dudeney number or not.

Example: Consider the number 512.

7. Write a program to display prime numbers from 10 to 500


8. Write a program to display perfect numbers from 10 to 500
9. Write a program to display palindrome numbers from 10 to 500

10. Write a program to input a number and find whether the number is an emrip number or
not. A number is called an emirp number if we get another prime number on reversing
the number itself. In other words, an emirp number is a number that is prime forwards or
backward. It is also known as twisted prime numbers.
Eg. Input n = 79, 79 and 97 both are prime numbers. Hence, 79 is a prime number.

11. Write a program to input a number. Check and display whether it is a Niven number or
not. (A number is said to be Niven which is divisible by the sum of its digits).

Example: Sample Input 126


Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.

12. Palindrome Number in Java: Write a program to accept a number from the user and
check whether it is a Palindrome number or not. A number is a Palindrome which when
reads in reverse order is same as in the right order.

Sample Input: 242


Sample Output: A Palindrome number

13. Write a program in Java to accept a number. Check and print whether it is a prime
number or not. A prime number is a number which is divisible by 1 and itself only.

For example 2, 3, 5, 7, 11, 13 etc… are all prime numbers.

2
14. Write a program in Java to accept a number. Check and print whether it is a Perfect
number or not: (A number is called Perfect if it is equal to the sum of its factors other
than the number itself.)

Example: 6 = 1 + 2 + 3

15. A special two-digit number is such that when the sum of its digits is added to the
product of its digits, the result is equal to the original two-digit number.

Example:
Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of sum of digits and product of digits = 14 + 45 = 59

16. Armstrong number program. A positive number is an Armstrong number if it is equal


to the sum of cubes of its digits. 1, 153, 370, 371, 407 are a few examples of Armstrong
number.

Taking 153 as an example:


Sum of cube of digits
= (1 x 1 x 1) + (5 x 5 x 5) + (3 x 3 x 3)
= 1 + 125 + 27
= 153

17. Program to print 10 to 500 Armstrong number.

You might also like