Computer Science, asked by jerefreddy, 2 months ago

Write a Java program to input an integer. Find and print sum of all even digits and product of odd digits.​

Answers

Answered by BrainlyProgrammer
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 ommprakash26
0

Explanation:

Hope you understand this program

Attachments:
Similar questions