Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array Last Updated : 12 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an array of integers, the task is to find whether it's possible to construct an integer using all the digits of these numbers such that it would be divisible by 3. If it is possible then print "Yes" and if not print "No". Examples: Input : arr[] = {40, 50, 90} Output : Yes We can construct a number which is divisible by 3, for example 945000. So the answer is Yes. Input : arr[] = {1, 4} Output : No The only possible numbers are 14 and 41, but both of them are not divisible by 3, so the answer is No. Java // Java program to find if it is possible // to make a number divisible by 3 using // all digits of given array import java.io.*; import java.util.*; class GFG { public static boolean isPossibleToMakeDivisible(int arr[], int n) { // Find remainder of sum when divided by 3 int remainder = 0; for (int i = 0; i < n; i++) remainder = (remainder + arr[i]) % 3; // Return true if remainder is 0. return (remainder == 0); } public static void main(String[] args) { int arr[] = { 40, 50, 90 }; int n = 3; if (isPossibleToMakeDivisible(arr, n)) System.out.print("Yes\n"); else System.out.print("No\n"); } } // Code Contributed by Mohit Gupta_OMG <(0_o)> Output:Yes Time Complexity: O(n) Auxiliary Space: O(1) because it is not using extra space Please refer complete article on Possible to make a divisible by 3 number using all digits in an array for more details! Comment More infoAdvertise with us Next Article Java Program to Check Whether Number is Divisible by 5 K kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java Program to Check if all digits of a number divide it Given a number n, find whether all digits of n divide it or not.Examples: Input : 128 Output : Yes 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Input : 130 Output : No We want to test whether each digit is non-zero and divides the number. For example, with 128, we want to test d != 0 && 128 2 min read Pandigital Product A Pandigital Number is a number that makes the use of all digits 1 to 9 exactly once. We are given a number, we need to find if there are two numbers whose multiplication is given number and given three numbers together are pandigital. Examples: Input : 7254Output : Yes39 * 186 = 7254. We can notice 5 min read Java Program to Check Whether Number is Divisible by 5 Generic rules in mathematics to test divisibility by 5 in a number system is followed as numbers that end in 5 or 0 are divisible by 5. It doesn't matter how big the number is. Modulo operator will be used most frequently in programming when it comes down to divisibility. Knowledge of the range of n 4 min read Java Program for Count rotations divisible by 8 Given a large positive number as string, count all rotations of the given number which are divisible by 8. Examples: Input: 8 Output: 1 Input: 40 Output: 1 Rotation: 40 is divisible by 8 04 is not divisible by 8 Input : 13502 Output : 0 No rotation is divisible by 8 Input : 43262488612 Output : 4 Ap 3 min read Java Program to Find a triplet that sum to a given value Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. If there is such a triplet present in array, then print the triplet and return true. Else return false. Examples:Â Â Input: array = {12, 3, 4, 1, 6, 9}, sum = 24;Â Output: 12, 3, 9Â Explanation: There 7 min read Fizz Buzz Program in Java FizzBuzz is a game popular amongst kids that also teaches them the concept of division. In recent times it has become a popular programming question. Following is the problem statement for the FizzBuzz problem. Examples: Input: 9Output: FizzExplanation: The number is divisible by 3 only. Input: 25Ou 2 min read Like