Frequently Asked Java Program 12: Java Program To Find Divisors Of Given Number

Hello Folks,

As part of Frequently Asked Java Programs In Interviews For Freshers And Experienced, in this post we will see a Java program to Find Divisors Of Given Number.

Problem:

Write a JAVA program to find the divisors of a given number.

Solution:

  • Divisor is a number that divides  another number without a reminder or a number that divides an integer evenly.

Ex: 10/2= 5 (Here 2 is divisor.)

Logic 1:

  • Positive Divisor of a number N will be greater than or equal to 1 and less than or equal to number N.
  • For Ex: Say Number is 4. Divisor of 4 will be 1,2 and 4.
  • To get the divisor of a number N, we should divide N by all numbers in between 1 and N including 1 and N.
  • We will use modulus operator which gives reminder. If reminder is zero, we can say given number is divisible by another number.
  • For ex: 10%2= 0 (10 is divisible by 2 without a reminder)
  • 11%2=1 (11 is divisible by 2 with a reminder as 1)

Java Code:

Output: