WAP to enter a number and find the sum of even digit only
Answers
Answered by
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.
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
Computer Science,
6 months ago
Math,
6 months ago
English,
6 months ago
Math,
1 year ago
History,
1 year ago
Psychology,
1 year ago