Difference Between Sum Of Even and Odd Digits

Given a number the task is to find the difference between sum of even and odd digits of the number.

Example 1: Let us take a number 3471. Here sum of even digits is 4 and sum of odd digits is 11. Hence their difference is 11-4 = 7.

Example 2: Let us take a number 8316. Here sum of even digits is 14 and sum of odd digits is 4. Hence their difference is 14-4 = 10.

Java
import java.util.*;
public class DiffecrenceEvenOdd
{
    public static void main(String args[])
    {
        int n=0,r=0,eSum=0,oSum=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)
            {
                eSum=eSum+r;
            }
            else
            {
                oSum=oSum+r;
            }
          n=n/10;
        }
        if(eSum>oSum)
        {
            System.out.println("The difference between the sum of odd and even numbes is "+(eSum-oSum));
        }
        else
        {
            System.out.println("The difference between the sum of odd and even numbes is "+(oSum-eSum));
        }
    }
}
Java