为什么我要用java。lang.NullPointerException在我的程序中?我看不出有什么问题
这是一个寻找任何数字中最大prme因子的程序
// Program to get the largest prime factor of a number
import java.util.*;
class factor{
ArrayList<Long> a;
public void large(long n){
for(long i = 1; i <= n; i++){
if (n % i == 0){
a.add(i);
}
}
System.out.println(Collections.max(a));
}
}
class test{
public static void main(String[] args){
factor g = new factor();
g.large(13195);
}
}
共 (0) 个答案