Java Program on Special Number
- Categories Java
Accept a number from user and print if given number is special number or not.
Special number: A special number is a number whose Sum of digits plus product of digits it is equal to original number. e.g
For example 59 = 5 + 9 + (5×9)
=59.
import java.util.Scanner; public class SpecialNumber { public static void main() { Scanner sc = new Scanner(System.in); int n; System.out.println("Enter any number:"); n= sc.nextInt(); int m = n;
int sum = 0, prod = 1;
while (n != 0) {
int d = n%10;
sum = sum + d;
prod = prod * d;
n = n / 10;
}
if ( sum + prod == m)
System.out.println ("yes");
else
System.out.println ("no"); } }
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021