I made this simple program that prints out all the factors of a given number. The only problem is that it prints out the numbers in different order...For example:
factors of 12:
1*12
2*6
3*4
but this is what my program prints out:
1*12
2*6
3*4
4*3
6*2
12*1
It's taking the numbers and just switching the order, and I was wondering if anyone knew how I could get rid of that.
import java.io.*;
import java.util.*;
public class Factorizer
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Number to factor --> ");
int limit = Integer.parseInt(br.readLine());
System.out.println("\n\n<-- Factors --> ");
ArrayList firstOperand = new ArrayList();
ArrayList secondOperand = new ArrayList();
for (int i=1; i<=limit; i++)
{
for (int j=limit; j>=1; j--)
{
if (j *i == limit)
{
System.out.println(i+ " * " + j);
}
}
}
}
}