
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
To check whether it is possible to make a divisible by 3 number using all digits in an array, the Java code is as follows −
Example
import java.io.*; import java.util.*; public class Demo{ public static boolean division_possible(int my_arr[], int n_val){ int rem = 0; for (int i = 0; i < n_val; i++) rem = (rem + my_arr[i]) % 3; return (rem == 0); } public static void main(String[] args){ int my_arr[] = { 66, 90, 87, 33, 123}; int n_val = 3; if (division_possible(my_arr, n_val)) System.out.println("It is possible to make a number that can be divided by 3"); else System.out.println("It is not possible to make a number that can be divided by 3"); } }
Output
It is possible to make a number that can be divided by 3
A class named Demo contains a function named ‘divide_possible’. It checks to see if the numbers can be used to make a number that can be divided by 3. In the main function, an array with values, and an ‘n’ value is defined. The function is called with the specific arguments and the relevant message will be displayed on the console.
- Related Articles
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- C/C++ Program to check whether it is possible to make a divisible by 3 number using all digits in an array?
- C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?
- Possible to make a divisible by 3 number using all digits in an array in C++
- Number of digits to be removed to make a number divisible by 3 in C++
- Java Program to check if all digits of a number divide it
- C Program to check if a number is divisible by sum of its digits
- C Program to check if a number is divisible by any of its digits
- Check whether it is possible to make both arrays equal by modifying a single element in Python
- C Program to Check if all digits of a number divide it
- PHP program to check if all digits of a number divide it
- Check whether product of digits at even places of a number is divisible by K in Python
- Check whether sum of digits at odd places of a number is divisible by K in Python
- Check whether 974 is divisible by 3 or not.
- Java program to check whether the given number is an Armstrong number

Advertisements