Input a natural number >1 and output its prime factors

import java.io.*;
import java.lang.*;
class p{
static int i,c;
static int prim(int n)
{
c=0;
for(i=1;i<=n;i++)
if(n%i==0)
c=c+1;

if(c==2)
{
System.out.print(n+",");
return(1);

}
else
return(0);
}
public static void main(String args[])throws Exception{
int no=Integer.parseInt(args[0]);

while(no>=2)
{
for(int j=2;j<=no;j++)
{
if(no%j==0&&prim(j)==1)
{
no=no/j;
break;

}
}
}
System.out.print('\b');
}
}

Post a Comment