package com.tutorial4u;
import java.util.Scanner;
public class SumOfEvenNumber {
public static void main(String[] args) {
int num,sum=0 ,rem;
System.out.print("Enter any number : ");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
while(num!=0){
rem = num %10;
num = num/10;
if(rem % 2==0){
sum = sum+rem;
}
}
System.out.println("Sum of even digit : "+sum);
}
}
Output :
Enter
any number : 4668778
Sum of
even digit : 32
No comments:
Post a Comment