0% found this document useful (0 votes)
3 views3 pages

Java Number Programs

java programming icse

Uploaded by

ashwee204
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java Number Programs

java programming icse

Uploaded by

ashwee204
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Number programs for practice

1. Write a program to input a three digit number. Use a method int Armstrong(int n) to accept
the number. The method returns 1, if the number is Armstrong, otherwise zero(0).

Sample Input: 153


Sample Output: 153 ⇒ 13 + 53 + 33 = 153
It is an Armstrong Number.

2. 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
Sample Input: 467
Sample Output: Not a Palindrome number

3. 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 are all prime numbers.

4. Write a menu driven program to accept a number from the user and check whether it is a Prime
number is an Automorphic number. Automorphic number: (Automorphic number is the number
which is contained in the last digit(s) of its square.)

Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.

5. Write a program to input a number and check and print whether it is a Pronic number or not.
[Pronic number is the number which is the product of two consecutive integers.]
Examples:
12 = 3 * 4
20 = 4 * 5
42 = 6 * 7

6. An Abundant number is a number for which the sum of its proper factors is greater than the
number itself. Write a program to input a number and check and print whether it is an Abundant
number or not.

Example:Consider the number [Link] of 12 = 1, 2, 3, 4, 6

Sum of factors = 1 + 2 + 3 + 4 + 6 = 16 As 16 > 12 so 12 is an Abundant number

7. 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.
8. Write a program to accept a number and check whether it is a 'Spy Number' or not. (A number is
spy if the sum of its digits equals the product of its digits.)

Example: Sample Input: 1124


Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8

9. 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 digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59

Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits.
If the value is equal to the number input, then display the message "Special two—digit number"
otherwise, display the message "Not a special two-digit number".

10. A prime number is said to be 'Twisted Prime', if the new number obtained after reversing the
digits is also a prime number. Write a program to accept a number and check whether the number
is 'Twisted Prime' or not.
Sample Input: 167
Sample Output: 761
167 is a 'Twisted Prime'.

11. Write a program to enter two numbers and check whether they are co-prime or not.
[Two numbers are said to be co-prime, if their HCF is 1 (one).]
Sample Input: 14, 15
Sample Output: They are co-prime.

12. A number is said to be Duck if the digit zero is (0) present in it. Write a program to accept a
number and check whether the number is Duck or not. The program displays the message
accordingly. (The number must not begin with zero)
Sample Input: 5063
Sample Output: It is a Duck number.
Sample Input: 7453
Sample Output: It is not a Duck number.

13. Write a program to accept a number from the user and check whether it is a Palindrome
number Example: 11, 101, 151 etc.
14. Write a program to accept a number from the user and check whether it is a a Perfect number.
Example: 6 = 1 + 2 + 3

15. 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.

Sum of digits = 5 + 1 + 2 = 8
Cube root of 512 = 8

As Sum of digits = Cube root of Number hence 512 is a Dudeney number.

16. A tech number has even number of digits. If the number is split in two equal halves, then the
square of sum of these halves is equal to the number itself. Write a program to generate and print
all four digits tech numbers.

Example:

Consider the number 3025

Square of sum of the halves of 3025 = (30 + 25)2


= (55)2
= 3025 is a tech number.

17. Write a program to input a number and count the number of digits. The program further
checks whether the number contains odd number of digits or even number of digits.

Sample Input: 749


Sample Output: Number of digits=3
The number contains odd number of digits.

18. Write a program to input a number and display the new number after reversing the digits of
the original number. The program also displays the absolute difference between the original
number and the reversed number.

Sample Input: 194


Sample Output: 491
Absolute Difference= 297

19. The Greatest Common Divisor (GCD) of two integers is calculated by the continued division
method. Divide the larger number by the smaller, the remainder then divides the previous divisor.
The process repeats unless the remainder reaches to zero. The last divisor results in GCD.

Sample Input: 45, 20


Sample Output: GCD=5

You might also like