Working on a task where I should factorize a prime number. Here's the solution I've come up with:
import java.util.Scanner;
public class Task8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Which number to factorize:");
int number = input.nextInt();
System.out.println();
int counter = 1;
for (int i = 2; i <= number; i++) {
while (number % i == 0) {
if (counter == 1 && i == number) {
System.out.println("The number is a prime, can’t be factorized.");
break;
} else {
System.out.println("Prime" + " " + "#" + counter + ":" + " " + i);
number = number/i;
++counter;
}
}
}
}
}
However, a book I'm currently studying, strongly advices against using break statements in loops. So how would I do without one in this case?
Cheers!