Ok, I've got this code, it says that there are no main classes and that public class Amicable; class Amicable is public, should be declared in a file named Amicable.java, but the file name is Amicable... Any help would greatly help me, since I have same prob. with another file>_>
public class Amicable
{
public Amicable() {
}
int duplicates = 0;
public int findAddFactors(int num)
{
int factorSum = 1;
for (int i=2; i<=(num /2); i++)
{
if ((num%i)==0)
factorSum+=i;
}
return factorSum;
}
public String areAmicable(int num)
{
if (num!=duplicates)
{
int pair1 = findAddFactors(num);
int pair2 = findAddFactors(pair1);
if ((num==pair2) && (pair1!=pair2))
{
duplicates = pair1;
return "("+pair2+","+pair1+")";
}
else
return null;
}
else
return null;
}
public static void main(String args[])
{
Amicable test = new Amicable();
for (int i=1; i<=100000;i++)
{
String res = test.areAmicable(i);
if (res!=null)
System.out.println(res);
}
}
}