To check if the count of divisors is even or odd, the Java code is as follows −
Example
import java.io.*; import java.math.*; public class Demo{ static void divisor_count(int n_val){ int root_val = (int)(Math.sqrt(n_val)); if (root_val * root_val == n_val){ System.out.println("The number of divisors is an odd number"); }else{ System.out.println("The number of divisors is an even number"); } } public static void main(String args[]) throws IOException{ divisor_count(25); } }
Output
The number of divisors is an odd number
A class named Demo contains a function named ‘divisor_count’, that checks if the number of divisors of the specific number is an even value or an odd number. In the main function, the ‘divisor_count’ is called with a value defined. Relevant message is displayed on the console.