Computer Science, asked by Cynthia35, 3 days ago

Write a program to take input of two decimal numbers, find the sum, then check whether the sum is even or odd.​

Answers

Answered by sarwa
0

Answer:

public static void main(String[] args) {

   // TODO Auto-generated method stub

   System.out.print("Enter number so it could be added: ");

   Scanner input = new Scanner(System.in);

   int sum = 0;

   int num = input.nextInt();

   while (num > 0){

       int digit = num % 10;

       num /= 10;

       sum += digit;

   }

   if (sum % 2 ==0){

               System.out.println("Even");

           }

           else{

               System.out.println("Odd");

           }

           System.out.println("The Sum of the digits is: " + sum);

               }

        /*

        //this is what i put, but was wrong.  

          sum = sum + num;

          num = num / 10;

       System.out.println("Sum of digits: " + sum);

       //ends here

        */

Answered by Supriya5879
0

Answer:

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.print("Enter number so it could be added: ");

Scanner input = new Scanner(System.in);

int sum = 0;

int num = input.nextInt();

while (num > 0){

int digit = num % 10;

num /= 10;

sum += digit;

}

if (sum % 2 ==0){

System.out.println("Even");

}

else{

System.out.println("Odd");

}

System.out.println("The Sum of the digits is: " + sum);

}

/*

//this is what i put, but was wrong.

sum = sum + num;

num = num / 10;

System.out.println("Sum of digits: " + sum);

//ends here

*/

{ }

OUTPUT

Enter number so it could be added: 12334

Odd

The Sum of the digits is: 13

Share Improve thi

Similar questions