print sum of even and odd digits.

WAP to print sum of even and odd digits.

import java.util.*;

class E4SumOfEvenOddDigits

{

    public static void main()

    {

        int x,l;

        int even=0,odd=0;

        System.out.println("Enter any integer \n\n\n");

        Scanner in = new Scanner(System.in);

        x = in.nextInt();

        

        while(x>0)

        {

            l= x %10;

            if (l%2==0)

            even= even + l;

            else

            odd = odd +l;

            x=x/10;

        }

        System.out.println("Sum of odd digits is " +odd );

        System.out.print("Sum of even digits is " +even );

    }

}



For Any Desired Program comment below. WE WILL TRY OUR BEST TO MAKE THAT PROGRAM AVAILABLE.

Comments

Popular Posts