Challenge: Filtering Numbers in a Loop
Task
Swipe to start coding
Find the sum of all numbers from 1 to n
, excluding those that are divisible by 3 or 5.
- Create a method called
sumNotDivisibleBy3Or5(int n)
that returns anint
. - Inside this method, create a
for
loop that iterates from 1 ton
(inclusive). - In each iteration, check if the number is not divisible by 3 and not divisible by 5.
- If the number passes the condition, add it to a running total
sum
. - Return the total
sum
after the loop ends.
Solution
solution.java
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 8
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.7
Challenge: Filtering Numbers in a Loop
Swipe to show menu
Task
Swipe to start coding
Find the sum of all numbers from 1 to n
, excluding those that are divisible by 3 or 5.
- Create a method called
sumNotDivisibleBy3Or5(int n)
that returns anint
. - Inside this method, create a
for
loop that iterates from 1 ton
(inclusive). - In each iteration, check if the number is not divisible by 3 and not divisible by 5.
- If the number passes the condition, add it to a running total
sum
. - Return the total
sum
after the loop ends.
Solution
solution.java
Everything was clear?
Thanks for your feedback!
Awesome!
Completion rate improved to 2.7SectionΒ 3. ChapterΒ 8
single