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

Java code analysis of prime factors of a number decomposition

高洛峰
Release: 2017-03-19 11:02:15
Original
1497 people have browsed it

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);
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template