Computer Science, asked by madhavrnair05, 18 hours ago

Write a program in java to print the value of the sum of the digits of an integer that are divisible by only 2 and 3

Answers

Answered by Anonymous
5

Below is the implementation of above approach: C++ Java.

...

Method #2: Using string:

  1. Convert the given number to a string by taking a new variable.
  2. Traverse the string, Convert each element to integer and add this to sum.
  3. If the number is divisible by sum then print Yes.
  4. Else print No.
Answered by William001
6

Explanation:

Given an integer N, the task is to check whether the number is divisible by the sum of its digits or not. If divisible, then print “YES” else print “NO”.

Examples:

Input: N = 12

Output: YES

Explanation:

As sum of digits of 12 = 1 + 2 = 3

and 12 is divisible by 3

So the output is YES

Input: N = 123

Output: NO

Similar questions