-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
  • 298,294
  • 41
  • 291
  • 462
GoZaddy
  • 33
  • 3

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
  • 10,745
  • 4
  • 30
  • 53