1.

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

Answer» 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.


Discussion

No Comment Found