Java program for Divine divisors problem

Algorithm to solve the Divine Divisors Problem

Divine Divisors Problem

Divine Divisor problem is one of the easy problems asked in code vita. In this problem, we need to find the divisors of the given number and print them in increasing order. Here is the Java program to solve the Divine divisor problem to find the divisors of given number. The problem is not much difficult until you know about the divisor. A divisor is a number less than the given number and divides completely and gives the remainder as 0[zero].

Problem Description

Question -: Print a line containing all the divisors in increasing order separated by space.

Input Format: The first line of input contains an integer ‘N’ denoting the number.

Output Format: Print a line containing all the divisors in increasing order separated by space.

Constraints:
1 <= N <= 10^8

S.noInputOutput 
1101 2 5 10 
    
Java program to solve the Divine divisor problem

How do you find divisors?

If a number less then the given number divides the given number completely and leaves the remainder as 0[zero] then the number is considered as the divisor the number.

Java code to find the divisors of the given number is:

for(int i=1;i<number+1;i++){
    if(number % i == 0){
        System.out.print(i + " ");
    }
}

This code will print the divisors of the given number

Java Code to find all divisors of the given number

import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    //initialize scanner class for user input
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter Number :");
		int N = sc.nextInt();
		//Start a for loop to find the divisors
		for(int i=1;i<N+1;i++){
		    //Check for divisors
		    if(N % i == 0){
		        //print divisors
		        System.out.print(i + " ");
		    }
		}
	}
}
Output:
Enter Number :
10
1 2 5 10

Divine Divisors Problem in Other Coding Languages

C

To find the solution of Divine Divisors Problem in C Programming language click on the button below:

C

C++

To find the solution of Divine Divisors Problem in C++ Programming language click on the button below:

C++

 

Python

To find the solution of Divine Divisors Problem in Python Programming language click on the button below:

Python

One comment on “Java program for Divine divisors problem”