![special number](https://simplycoding.in/wp-content/uploads/2020/04/special-number-2.jpg)
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 Single Linked List Programs in Java](https://simplycoding.in/wp-content/uploads/2021/07/Single-Linked-List-Programs-in-Java-300x200.png)
Single Linked List Programs in Java
28 August, 2021
![Implementing Stack using Array in Java Implementing Stack using Array in Java](https://simplycoding.in/wp-content/uploads/2021/08/Implementing-Stack-using-Array-in-Java-300x200.png)
Implementing Stack using Array in Java
28 August, 2021
![Constructor Programs Constructor Programs](https://simplycoding.in/wp-content/uploads/2021/06/Constructor-Programs-300x200.jpg)
Constructor Programs
3 July, 2021