Computer Science, asked by sonam334, 1 year ago

WAP to enter a number and find the sum of even digit only

Answers

Answered by AqeelAhmad
1
import java.util.Scanner;

class Test
{
public static void main(String args[])
{
int n, r, s = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number :");
n = sc.nextInt();
while (n > 0)
{
r = n % 10; if (r % 2 == 0)
{
s = s + r;
}
n = n / 10;
}
System.out.print("\nSum of Even Digits :" + s);
}
}

Hope it helps you.
Similar questions