- Related Questions & Answers
- Check if a large number is divisible by 3 or not in C++
- Check if a large number is divisible by 11 or not in java
- Check if a large number is divisible by 2, 3 and 5 or not in C++
- Check if a large number is divisible by 11 or not in C++
- Check if a large number is divisible by 25 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 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++

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

If the sum of the digits of a number is divisible by 3, then the number is divisible by 3.

Some examples of numbers divisible by 3 are as follows.

- The number 85203 is divisible by 3 because the sum of its digits (8 + 5 + 2 + 0 + 3 = 18) is divisible by 3.
- The number 79154 is not divisible by 3 because the sum of its digits (7 + 9 + 1 + 5 + 4 = 26) is not divisible by 3.

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

Enter a number : 85203 Given number is divisible by 3

Advertisements