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
5
Below is the implementation of above approach: C++ Java.
...
Method #2: Using string:
- Convert the given number to a string by taking a new variable.
- Traverse the string, Convert each element to integer and add this to sum.
- If the number is divisible by sum then print Yes.
- Else print No.
Answered by
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