Home  >  Article  >  Java  >  Java code analysis of prime factors of a number decomposition

Java code analysis of prime factors of a number decomposition

高洛峰
高洛峰Original
2017-03-19 11:02:151315browse

This article introduces Java code analysis of prime factors of number decomposition

import java.util.Scanner;

/**
 * Created by Admin on 2017/3/18.
 */
public class Test01 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,n;
        n=scan.nextInt();
        System.out.print(n+"=");
        for (i=2;i<=n;i++){
            while (n!=i){
                if(n%i==0) {
                    n = n / i;
                    System.out.print(i+"*");
                }
                else break;;
            }
        }
        System.out.println(n);
    }
}

Java code analysis of prime factors of a number decomposition

The above is the detailed content of Java code analysis of prime factors of a number decomposition. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn