OneCompiler

Finding the sum and product of the digits of a given number

194

Write a program to find the sum and product of the digits.

import java.util.*;

public class suprodi {
public static void main(String[] args) {
int sum=0,product=1;
Scanner sc = new Scanner (System.in);
System.out.println("ENTER A NUMBER : ");
int num=sc.nextInt();
int t=num;
while(t>0)
{
int d=t%10;
sum+=d;
product*=d;
t/=10;
}
System.out.println("SUM : "+ sum + " PRODUCT : " + product);
}
}

TO FIND OUTPUT : CLICK>> https://onecompiler.com/java/3ydv9gefx