Write a java program to find Sum of Squares of Even Digits.

Write a program to read a number, calculate the sum of squares of even digits (values) present in the given number.

Input and Output Format:

Input consists of a positive integer n.

Output is a single integer .

Refer sample output for formatting specifications.

Sample Input 1:

56895

Sample Output 1:

100

Sum of Squares of Even Digits in java.

 

import java.util.Scanner;

public class Main3 {
public static void main(String[] args) {
  Scanner input= new Scanner(System.in);
  int number = input.nextInt();
  int n1=0,n2=0;
    while(number!=0)
    {
    n1=number%10;
    if((n1%2)==0)
    n2+=n1*n1;
    number/=10;
    }
   System.out.println(n2);
}
}

Leave a Reply

Your email address will not be published.

twenty + six =