So for my assignment, I have to write a program that asks the user for an integer input and then print out that number\'s prime factorization. This is what I have:
You are almost there! Move the if-continue block outside the for loop. Otherwise, it "continues" the inner-most loop, rather than the one you intended.
while (number % i == 0) {
number /= i;
count++;
}
if (count == 0) {
continue;
}
System.out.println(i+ "**" + count);
Alternatively, you could enclose the System.out.println call in if (count != 0), because it's the only statement following the continue:
while (number % i == 0) {
number /= i;
count++;
}
if (count != 0) {
System.out.println(i+ "**" + count);
}
Your program on ideone: link.