- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

With a given long integer n, write a program to find the difference between sum of the odd digits and even digits to be 0 or not. Index starts from 0.

n = 1212112 Sum of odd position elements = 2 + 2 + 1 = 5 Sum of even position elements = 1 + 1 + 1 + 2 = 5 Difference = 5 - 5 = 0 Output = Yes

Following is the program in Java to find the required output.

class JavaTester { public static int difference(int n){ return (n % 11); } public static void main(String args[]){ int n = 1212112; System.out.println("Number: " + n); System.out.println(difference(n) == 0 ? "Yes" : "No"); n = 12121121; System.out.println("Number: " + n); System.out.println(difference(n) == 0 ? "Yes" : "No"); } }

Number : 1212112 Output: Yes Number : 12121121 Output: No

- Related Questions & Answers
- C Program for Difference between sums of odd and even digits?
- Python Program for Difference between sums of odd and even digits
- C Program for the Difference between sums of odd and even digits?
- Difference between sums of odd level and even level nodes of a Binary Tree in Java
- Difference between sums of odd position and even position nodes of a Binary Tree in Java
- Count number of ordered pairs with Even and Odd Sums in C++
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime in C++
- Odd even index difference - JavaScript
- Count even and odd digits in an Integer in C++
- Sum of individual even and odd digits in a string number using JavaScript
- Count odd and even digits in a number in PL/SQL
- Find the sum of digits of a number at even and odd places in C++
- Absolute Difference of even and odd indexed elements in an Array (C++)?
- Find even odd index digit difference - JavaScript

Advertisements