
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If Count of Divisors Is Even or Odd in Java
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.
Advertisements