Code Here:
The factors are:
1 2 5 10
The prime factors are :
2 5
import java.util.*;
class primefactor
{
public static void main(String s[])
{
int i,n,j=0,count=0 ;
Scanner sc=new Scanner(System.in);
int a[]=new int[10];
System.out.print("Enter the value of nth no. of place : ");
n=sc.nextInt();
System.out.println("The factors are:");
for(i=1;i<=n;i++)
{
if(n%i==0)
{
a[j++]=i;
}
}
for(i=0;i<j;i++)
System.out.println(a[i]+"\t");
System.out.println("The prime factors are:");
for(i=0;i<j;i++)
{
count=0;
for(int k=1;k<=a[i];k++)
{
if(a[i]%k==0)
count++;
}
if(count==2)System.out.print("\t"+a[i]);
}
}
}
Output:
Enter the value of nth no. of place: 10The factors are:
1 2 5 10
The prime factors are :
2 5
0 Comments