[Solved] #JAVA – Programme calculates the sum of numbers from 1 to 10,000 (including 1 and 10,000) omitting numbers numbers whose hundred digit is 2 or 3 [closed]


You can use modulus to find the last 3 digits and then check that with your condition.

   public printNum() {
        int num = 0;
        while (num < 10000) {
            num++;
            int last3Digits = num % 1000;
            if (!(last3Digits >= 200 || last3Digits <= 399)){
                System.out.println(num);
            }
        }
    }

Hope this solves it

3

solved #JAVA – Programme calculates the sum of numbers from 1 to 10,000 (including 1 and 10,000) omitting numbers numbers whose hundred digit is 2 or 3 [closed]