Special two digit number - Java Programs

Java complied and working program for Special two digit number
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 the sum of digits and product of digits= 14 + 45 = 59
  import java.util.*;
public class special_2digit
{
    public static void main (String args[])
    {
        Scanner in = new Scanner (System.in);
        int num,d;
        
        double sum=0.0,p=1;
        System.out.println("Enter the numbers");
        num=in.nextInt();
        int n=num;
       
        while(num>0)
        {
            d=num%10;
            sum=sum+d;p=p*d;
            num=num/10;
        }
        if(n==sum+p)
        System.out.println("Special 2 digit number");
        else if(n!=sum+p)
        System.out.println("Not special");
    }
    }


Comments

Popular posts from this blog

Practice questions for English grammar

Physics 2017 Solved Paper Physics

Computer applications icse board exam paper solved 2017