Write a Java program to input an integer. Find and print sum of all even digits and product of odd digits.
Answers
Answered by
4
Answer:
import java.util.*;
class Num{
public static void main (String ar[]){
System.out.println("Enter a number");
int num=sc.nextInt();
int s=0,p=1;
while(num!=0){
int d=num%10;
if(d%2==0)
s+=d;
else
p*=d;
num/=10;
}
System.out.println("Sum="+s+"\nProduct="+p);
}
}
Variable Description:-
- num:- number
- s:- sum variable
- p:- product variable
- d:- digit variable
Answered by
0
Explanation:
Hope you understand this program
Attachments:
Similar questions
Hindi,
1 month ago
Computer Science,
1 month ago
Science,
2 months ago
Math,
2 months ago
Accountancy,
9 months ago
Math,
9 months ago