Use the remainder operator (also known as the modulo operator) which returns the remainder of the division and check if it is zero:
if (j % 4 == 0) {
// j is an exact multiple of 4
}
More Related Contents:
- How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Java FileWriter with append mode
- How to resolve Java UnknownHostKey, while using JSch SFTP library?
- Hibernate Criteria returns children multiple times with FetchType.EAGER
- Simple export and import of a SQLite database on Android
- SCJP6 regex issue
- ByteBuffer.allocate() vs. ByteBuffer.allocateDirect()
- Why generate long serialVersionUID instead of a simple 1L?
- When should we use a PreparedStatement instead of a Statement?
- Auto-wiring a List using util schema gives NoSuchBeanDefinitionException
- Android Studio cannot resolve symbol but code executes correctly
- Calling static generic methods
- Non repeating random numbers
- How to locate the Path of the current project directory in Java (IDE)?
- Multiple submit buttons in the same form calling different Servlets
- How to convert byte array to hex format in Java
- Multiple indexes for a Java Collection – most basic solution?
- How many ways to convert bitmap to string and vice-versa?
- Error in setting JAVA_HOME
- How to exit an Android app programmatically?
- Why defining class as final improves JVM performance?
- Check date between two other dates spring data jpa
- Java Sorting: sort an array of objects by property, object not allowed to use Comparable
- bootstrap.yml configuration not processed anymore with Spring Cloud 2020.0
- How do I prevent JAXBElement from being generated in a CXF Web Service client?
- Recursive initializer works when I add “this”?
- When are API methods marked “deprecated” actually going to go away?
- java.lang.SecurityException: attempting to read gservices without permission
- Static method in Java can be accessed using object instance [duplicate]