Java Eclipse Euler 3 JUnit Test Case I solved Euler 3 on ja
Java Eclipse - Euler 3 JUnit Test Case?
I solved Euler 3 on java eclipse now I just need to create 2 JUnit test cases for my already existing code which should both pass.
package controller;
public class Euler3Solution {
    static boolean PrimeNum (long n)
    {
        //loop will increment i if i is less than or equal to n div. by 2
        for(long i=2; i<=n/2;i++)
        {
            //If the num is divisible by i with no remainder, it will be false
            if(n%i==0)
            {                      
                 return false;      
            }
        }
        return true;
    }
   
    //Statements inside will generate greatest prime num
    static long GreatestPrime (long n)
    {
        long largestPrimenumber=0;
       
        //if i is less than the sqrt of 600851475143/2, i will increment..
        for(long i=2; i<Math.sqrt(n)/2;i++)
        {
            //..until it is divisible to point of no remainder..
            if(n%i==0)
            {
                if(PrimeNum(i))
                {
                    //..if there is no remainder, that # will be largestPrimeNumber
                    largestPrimenumber = i;
                }
                 }
        }
        //to be able to get that # back
        return largestPrimenumber;
    }
   
    public static void main(String[] args) {
       
        System.out.println(GreatestPrime(600851475143L)); //Print out answer to console
       
}
}
Solution
public static void main(String[] args) {
       
        System.out.println(GreatestPrime(600851475143L)); //Print out answer to console
       
}
}
Ans:
6857


