Java – How to Check if integer is multiple of a number?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

You need to check if the integer number is a multiple of a number in Java.

Solution

Use the modulus operator and check the remainder to find it out. Below is a sample code snippet demonstrating how to find if the number is a multiple of 4.

public class Main {

    public static void main(String[] args) {
        int acinput = 12;
        int result = acinput %4;
        System.out.println(result);
    }
}
%d bloggers like this: