Write a program to find out all unique divisors of an integer For e.g. Input = 24 Output = 2, 3

Chikul
Posted by Chikul under Others category on | Views : 3252
import java.io.*;
import java.lang.*;

public class UniqueDivisors
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a no : ");


int i=Integer.parseInt(br.readLine());
int j,k;
j=i;
//int c=0;

for(k=2;k<=j;k++)
{
if(i%k==0)
{
//System.out.println(k);
int c=0;
for(int x=1;x<=k;x++)
{

if(k%x==0)
{
c++;
}
}
if(c<3)
{
System.out.println(k);
}

}
}
}
}

Comments or Responses

Login to post response