output is supposed to look something like:

"Enter choice:

P just to determine if a number is prime.

F to factor the number as well.

Q to quit:

Choice : F

Enter the number : 4

The number 4 factors as follows:

4 = 2 * 2

The number 4 is composite.

Enter choice:

P just to determine if a number is prime.

F to factor the number as well.

Q to quit:

Choice : P

Enter the number : 3

3 is prime.

Enter choice:

P just to determine if a number is prime.

F to factor the number as well.

Q to quit:

Choice : Q

Bye!"

but my factors are not coming out right (or at all) and i do not know how to loop the program so that you can enter as many numbers as you want before hitting Q and "ending" the program. any help would be appreciated. here is my sloppy code that someone already helped me with.

Code:

import java.util.*;
public class FindPrime2
{
public static void main(String[] args)
{
run();
}
public static void run()
{
String choice = "";
int num = 0;
ArrayList factors;
Scanner scan = new Scanner(System.in);
System.out.println("Enter choice:");
System.out.println("P to just determine if a number is prime.");
System.out.println("F to factor the number as well.");
System.out.println("Q to quit.");
System.out.print("Choice : ");
choice = scan.nextLine();
if (choice.equalsIgnoreCase ("Q"))
System.out.print("Bye!");
if (choice.equalsIgnoreCase ("P"))
{
System.out.print("Enter the number : ");
num = scan.nextInt();
if (Factor.isPrime(num))
System.out.println(num + " is prime.");
else
System.out.println(num + " is not prime.");
}
if (choice.equalsIgnoreCase ("F"))
{
System.out.print("Enter the number : ");
num = scan.nextInt();
factors = Factor.getFactors(num);
if (factors.size() < 1)
System.out.println(num + " is prime.");
else
{
System.out.println("The number " + num + " factors as follows:");
System.out.print(num + " = " + factors.get(0));
for (int count = 1; count < factors.size(); count++)
System.out.print(" * " + factors.get(count));
System.out.println();
System.out.println("The number " + num + " is composite.");
}
}
else
System.out.println("Sorry, Invalid Choice.");
System.out.println();
}
}

and

Code:

import java.util.*;
public class Factor
{
public static boolean isPrime(int num)
{
//if there is no factors, isPrime is true
return getFactors(num).size() == 0;
}
//arraylist was only way i find to return factors
public static ArrayList getFactors(int num)
{
ArrayList list = new ArrayList();
int factor;
while(num > 1)
{
factor = 2;
//finds all factors of number by increasing divisor
while (num % factor != 0 && num != factor)
factor++;
//adds each new factor to array list
if (num != factor)
list.add(new Integer(factor));
num = num / factor;
}
return list;
}
}