program to print sum of all even digits in a number.

import java.util.*;

public class ved{

public static void main(String[] args){

Scanner sc= new Scanner(System.in);

System.out.print("enter a number=");

int n=sc.nextInt();

int rm,sum=0;

while(n>0){

     rm=n%10;

if(rm%2==0)

{

     sum=sum+rm;

}

n=n/10;

   }

   System.out.print("the sum  is="+sum);

}

}


output-->

enter a number=456789

the sum  is= 18

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.