Computer Science, asked by jainreena7355, 6 months ago

write a program to input a number and find the sum of all even digits​

Answers

Answered by SparklyGeogony
36

Answer:

   Take a number.

   Declare a variable evenDigitSum to store the sum value and initialize it with 0.

   Find the last digit of the number.

   Check that the last digit is even or not.

   If it even then adds it to evenDigitSum variable, else go to next step.

   Remove the last digit of the number.

Explanation:

Answered by abhay03ac
1

Answer:

import java.util.Scanner;

class su

{int sum;

Scanner sc=new Scanner(System.in);

public void main(String args[])

{

System.out.println("please enter your number");

int n=sc.nextInt();

int sue=sued(n);

System.out.println("the sum of odd digits in your number is: "+sue);  

}

int sued(int l)

{

   int a;

     if(l<=0)

{

 

} else{

      a=l%10;

    if(a%2==0)

{

sum=sum+a;

}

sued(l/10);

}

return sum;

}

}

Explanation:

Similar questions