Sum Of Even Digits

Given a number the task is to find the sum of even digits present in the number.

Example 1: Let us take a number 3412. Here sum of even digits is 4+2=6.

Java
import java.util.*;
public class EvenDigitSum
{
    public static void main(String args[])
    {
        int n=0,r=0,sum=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)
            {
                sum=sum+r;
            }
            n=n/10;
        }
        System.out.println("Sum of even digits: "+sum);
    }
}
Java