Computer Science, asked by shwetajais886, 7 months ago

write a Java program to input a number and check whether it is a sum product or not​

Answers

Answered by peeyush321kumar
2

144  let the number be 144

1+4+4=9  sum of digits of the number

1*4*4=16  product of the digits number

9*16=144  product of Sum of digits and product of digits are equal to the number which the user input then that number is called Sum_product Number:

Hope it helps

import java.util.Scanner;

class SUMPRODUCT

{

public static void main(String[] args)

{

 Scanner myObj = new Scanner(System.in);

 System.out.print("Enter The Number to be checked: ");

 int num = myObj.nextLine();  

 int temp=num;

 int rem,digit,sum=0,pro=1;

 while(temp>0)

 {

  rem= temp%10;

  sum=sum+rem;

  pro=pro*rem;

  temp=temp/10;

 }

  if ((sum*pro == num))

  {

   System.out.print("Number is Sum_Product");

  }

  else

  {

   System.out.print("Number is the Sum_Product");

  }

}

}

Similar questions