今天的作业,实在想不出怎么做,百度的,有点羞愧
/*
将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
*/
import java.util.Scanner;
class HomeWork30
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.print(num+"=");
for (int i=2; i<=num;i++ )
{
while (num !=i)
{
if (num % i == 0)
{
System.out.print(i);
num = num/i;
System.out.print("*");
}
else
{
break;
}
}
}
System.out.println(num);
}
}
|
|