题目:题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。
解题过程也很简单,下面直接上代码了:
import java.util.ArrayList;
import java.util.Scanner; public class decompose {
ArrayList<Integer> list = new ArrayList<Integer>();
Scanner s = new Scanner(System.in);
int number = 2,value = 0; public static void main(String[] args) {
decompose d = new decompose(); d.function();
} private void function(){
value = Integer.parseInt(s.nextLine()); //从控制台输入一个数字进行测试 for(;number<=value;number++){
while(value%number==0){
list.add(number);
value = value/number;
}
}
for(int i:list){
System.out.println(i);
} } }
输入:90
输出:2
3
3
5