So, for my appointment, I need to write a program that asks the user for integer input, and then prints this digital factorization. This is what I have:
import java.util.Scanner; public class PrimeFactor { public static void main(String[] args) { System.out.print("Enter a positive number: "); Scanner scanner = new Scanner (System.in); int number = scanner.nextInt(); int count; for (int i = 2; i<=(number); i++) { count = 0; while (number % i == 0) { number /= i; count++; if (count == 0) { continue; } } System.out.println(i+ "**" + count); } } }
The problem that I have right now is that whenever I run it, for example, number 15453, I get a list of all factors from 1 to 100 and its indicator, when I need only the main factors, and I'm stuck like act.
Rikyc source share