Tuesday, 23 January 2018

Write a Java Program to Sum of all Even digit in Number.

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

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...