首页 > 代码库 > java编程题 --分解质因数

java编程题 --分解质因数

package Solve;

import java.util.Scanner;


public class Solve
{
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args)
	{
		System.out.println("请输入一个正整数:");
		int num = scan.nextInt();
		System.out.print(num + " = ");
		
		int k = 2;
		while ( k <= num )
		{
			if ( k == num )
			{
				System.out.println(num);
				break;
			}
			else if ( num % k == 0)
			{
				System.out.print( k + "*");
				num /= k;
			}
			else
				k++;
		}
	}
}


//题目: 将一个正整数分解质因数 . 例如: 90 = 2 * 3 * 3 * 5

  

java编程题 --分解质因数