- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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

# Check if a large number is divisible by 11 or not in java

A number is divisible by 11 if the difference between the sum of its alternative digits is divisible by 11.

i.e. if (sum of odd digits) – ( sum of even digits) is 0 or divisible by 11 then the given number is divisible by 11.

## Program

import java.util.Scanner; public class DivisibleBy11 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); String num = sc.nextLine(); int digitSumEve = 0; int digitSumOdd = 0; for(int i = 0; i<num.length(); i++) { if(i%2 == 0) { digitSumEve = digitSumEve + num.charAt(i)-'0'; } else { digitSumOdd = digitSumOdd + num.charAt(i)-'0'; } } int res = digitSumOdd-digitSumEve; if(res % 11 == 0) { System.out.println("Given number is divisible by 11"); } else { System.out.println("Given number is not divisible by 11"); } } }

#### Output

Enter a number : 121 Given number is divisible by 11

- Related Articles
- Check if a large number is divisible by 11 or not in C++
- Check if a large number is divisible by 3 or not in java
- Check if a large number is divisible by 25 or not in C++
- Check if a large number is divisible by 3 or not in C++
- Check if a large number is divisible by 5 or not in C++
- Check if a large number is divisible by 75 or not in C++
- Check if a large number is divisible by 8 or not in C++
- Check if a large number is divisible by 9 or not in C++
- Check if a large number is divisible by 13 or not in C++
- Check if any large number is divisible by 17 or not in Python
- Check if any large number is divisible by 19 or not in Python
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Check if a number is divisible by 23 or not in C++
- Check if a number is divisible by 41 or not in C++
- Check if a large number is divisible by 20 in C++

Advertisements