GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Maths/PrimeFactorization.java at master · tmluwei/Java Expand file tree/ Copy pathPrimeFactorization.javaMore file actions 32 lines (26 loc) · 696 Bytes / Copy pathPrimeFactorization.javaFile metadata and controls32 lines (26 loc) · 696 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 package Maths; import java.util.Scanner; public class PrimeFactorization { public static void main(String[] args) { System.out.println("## all prime factors ##"); Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int n = scanner.nextInt(); System.out.print(("printing factors of " + n + " : ")); pfactors(n); scanner.close(); } public static void pfactors(int n) { while (n % 2 == 0) { System.out.print(2 + " "); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { System.out.print(i + " "); n /= i; } } if (n > 2) System.out.print(n); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |