Write a program in java to find sum of only even number and its average from three digits number?

class Sum

{

                public static void main(String arg[])

                {

                                int a=258,d=0,s=0,c=0;

                                d=a%10;

                                if(d%2==0)

                                {

                                                s=s+d;   //s+=d;

                                                c++;

                                }

                                a=a/10;

                                d=a%10;

                                if(d%2==0)

                                {

                                                s+=d;     //s=s+d;

                                                c++;

                                }

                                a=a/10;

                                d=a%10;

                                if(d%2==0)

                                {

                                                s+=d;

                                                c++;

                                }

                                System.out.println("Total Sum "+s);

                                System.out.println("Average "+s/c);

                }

}

Sum & Average.PNG

, , , , , , ,

Leave a Reply