Java program for Factors and Sum of all factors of a given number

This java program will give you the no.of factors and sum of all the factors of a given number.

class Factor
{
public static void main (String args[])
{
int i,j=15,c=0,sum=0;
System.out.print(“Factors=  “);
for(i=1;i<=j;i++)
{
if(j%i==0)
{

System.out.print(i+”  “);
c++;
sum=sum+i;
}
}
System.out.println(“nsum of Factors=  “+ sum +”nno. of Factors=  “+ c);
//System.out.println(“no. of Factors=  “+ c);
}
}

Add Comment