If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.  Find the sum of all the multiples of 3 or 5 below 1000.Could someone point out if there is something wrong with the code; where I should optimize/modify it?import java.util.Scanner;public class SumBelowN {    private double getSum(int N) {        int n1 = 3;        int next_n1 = 3;        int n2 = 5;        int next_n2 = 5;        double sum = 0;        while (next_n1 < N || next_n2 < N) {            if (next_n1 == next_n2) {                sum += next_n1;                next_n1 += n1;                next_n2 += n2;                continue;            } else if (next_n1 < next_n2) {                sum += next_n1;                next_n1 += n1;                continue;            } else {                sum += next_n2;                next_n2 += n2;                continue;            }        }        return sum;    }    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int i = sc.nextInt();        // print the sum of all the numbers below 'i'        // which are divisible by both 3 and 5.        SumBelowN sumBelowN = new SumBelowN();        System.out.println(Sum:  + sumBelowN.getSum(i));        sc.close();    }}
Effeciency Project Euler #1
java;programming challenge
I'm assuming that you did read about the solution that runs in constant time, but wanted to add your own non-constant solution.continueYour continue statements are unnecessary; you can just remove them.NamingYour naming violates every standard for Java. Java uses camelCase and doesn't allow names to start with uppercase letters.It is also generally discouraged to use numbers in names if they can be avoided, which in this case they can: n1 could be called three, and n2 could be five. If you want to stay flexible, use firstMultiple and secondMultiple or something similarly expressive.ConstantsAs n1 and n2 are constants, I would declare them as static fields.CommentsAs your solution is not straightforward, I would add a comment or two about how it works.EfficiencyIn case you're interested, here are the results that I get if I compare your solution with the solutions from the other thread (mentioned in the comments):name                       per call (mean, ns)     per call (median, ns)     95th percentile (ns)     total (ms)     runsthree loops                280                     277                       256                      0.224          1000000without function calls     392                     392                       362                      0.3136         1000000getSum                     694                     695                       641                      0.5552         1000000with function calls        3739                    3766                      3338                     2.9912         1000000