Project Euler Problem 3 Java Solution - Largest Prime Factor

In this day and age, developers focus on technologies and frameworks. But it is equally important that we improve our logical skills - that is going back to basics. I highly recommend Project Euler to find such problems to challenge us. Below is a possible code that derives or finds the numerical answer to Euler Problem #3 with title - Largest Prime Factor.

Project Euler Problem #3 - Largest prime factor.

The problem number three given in the Project Euler Website is shown below:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
/**
 * A simple implementation to solve Euler Problem #3 - Largest prime factor.
 */
public class EulerProblemSolution {
    public static void main(String[] args) {
        long maxNumber = 600851475143l;
        long answer = maxNumber;
        for (long i = 2; i <= maxNumber / i; i++) {
            while (maxNumber % i == 0) {
                answer = i;
                maxNumber /= i;
            }
        }
        if (maxNumber>1) {
            answer = maxNumber;
        }
        System.out.println(answer);
    }
}

This program outputs the answer to the problem which is:

6857