- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between sums of odd and even digits.
Problem Statement
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.
Example
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
Example
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"); } }
Output
Number : 1212112 Output: Yes Number : 12121121 Output: No
Advertisements