/** * @author lautturi.com * Java example: Java get the Prime Factors of a Natural Number */ import java.util.*; public class Lautturi { public static void main(String[] args) { int n = 24; System.out.println("The Prime Factors of "+n+":"); for (int d = 2; n > 1; d++) for (; n % d == 0; n /= d) System.out.print(d+" ,"); } }Sourceual.www:tturi.com
output:
The Prime Factors of 24: 2 ,2 ,2 ,3 ,