# Java Program to count the divisors of a number ## Write a Java program to count the number of divisors of a number :

In this tutorial, I will show you how to find the total number of divisors for a number starting from 1. Let’s move through the steps first :

1. We are using one different method ‘findCountOfDivisors(int no)’ to find the count. This method will take one number as input and find the divisors count for that number.
2. First take the number from user using ‘Scanner’ class.
3. Now, pass the number to ‘findCountOfDivisors’ method.
4. Create one variable ‘result’ with initial value as ‘0’. This variable will store the final count.
5. Start one ‘for’ loop . This loop will start from i=1 and run till ‘i’ becomes equal to the number. ‘i’ will increase each time by 1.
6. Check if ‘i’ can divide the number or not. If ‘true’, increase the ‘result’ variable. That means, since ‘i’ is starting from 1 to that number, we will check for each numbers from ‘1 to that number’ if it can divide the number or not.
7. After the loop is completed, print the ‘result’

### Java Program :

``````/*
*
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*/

import java.util.Scanner;

/**
* Example Class
*/
public class ExampleClass {

/**
* System.out.println utility method
*
* @param value : value to print
*/
static void print(String value) {
System.out.println(value);
}

/**
* Method to find the count of divisors of a number
*
* @param no : number to find the count of divisors
* @return : no return value, just print the result
*/
static void findCountOfDivisors(int no) {

//variable to store the result
int result = 0;

//start a loop and check for each number if it can divide the given number
for (int i = 1; i <= no; i++) {
if (no % i == 0) {
//if the reminder is zero, increment the result variable
result++;
}
}

print("Total number of divisors : " + result);

}

/**
* main method for this class
*/
public static void main(String[] args) {

//variable to get the user input
int no;

//scanner object to get the user input
Scanner scanner = new Scanner(System.in);

print("Enter a number : ");

no = scanner.nextInt();

findCountOfDivisors(no);

}
}``````

### Sample Output :

``````Enter a number :
365
Total number of divisors : 4``````

### Where is the color and why codevscolor ?

Long story short, I love paintings and I paint on weekends. We(me and my wife) have one Youtube channel. Below is a video that I did recently. If you love this please do subscribe to support us 😊