-2

It is program to find the largest prme factor of any number.

// 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);
     }
}
user207421
  • 305,947
  • 44
  • 307
  • 483
GoZaddy
  • 37
  • 4

1 Answers1

0

You need to initialize your list, before invoking any method on it.

class Factor{

    List<Long> a = new ArrayList<>();

    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));
   }
}
Beri
  • 11,470
  • 4
  • 35
  • 57