printing factors with 2 classes
hi, i have a school project that asks for 2 classes to print factors of a number using 2 methods nextFactor and hasMoreFactors it does not specify if they are supposed to be void or not so... so far I'm at this-
Code Java:
public class chapter7number10
{
public chapter7number10(int a)
{
factor = a;
}
public void hasMoreFactors()
{
do
{
nextfactor();
System.out.println("one of the factor's is " + afactor);
}
while(afactor < factor);
}
public void nextfactor()
{
for(countingnumber = currentfactor; factor > countingnumber; countingnumber++)
{
currentfactor = currentfactor + countingnumber;
if(factor % currentfactor == 0)
{
afactor = currentfactor;
}
}
}
int factor;
int afactor = 0;
int currentfactor = 1;
int countingnumber = 1;
}
and the tester -
Code Java:
import java.util.*;
public class chapter7number10tester
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("What is your factor");
int a = in.nextInt();
chapter7number10 tester = new chapter7number10(a);
tester.hasMoreFactors();
}
}
this is printing an infinite loop of the first factor and i need it to print all the factors excluding 1 and itself then stop, please help.
Re: printing factors with 2 classes
Code :
public class chapter7number10 {
public chapter7number10(int a)
{
factor = a;
}
public void hasMoreFactors()
{
System.out.println("one of the factor's is " + afactor);
do
{
nextfactor();
System.out.println("one of the factor's is " + afactor);
}
while(afactor < factor);
}
public void nextfactor()
{
for(countingnumber = currentfactor +1; factor >= countingnumber; countingnumber++)
{
currentfactor = countingnumber;
if(factor % currentfactor == 0)
{
afactor = currentfactor;
break;
}
}
}
int factor;
int afactor = 1;
int currentfactor = 1;
int countingnumber = 1;
}
Re: printing factors with 2 classes
thanks for the code but i do not want it to print 1 and itself can you change that or no?
Re: printing factors with 2 classes
luck999, please read this carefully before you post again: http://www.javaprogrammingforums.com...n-feeding.html
If you continue spoonfeeding, let alone spoonfeeding incorrect answers, I'm going to ban you.