Challenge: Filtering Numbers in a Loop
Oppgave
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
forloop 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
sumafter the loop ends.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 22
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Fantastisk!
Completion rate forbedret til 2.86
Challenge: Filtering Numbers in a Loop
Sveip for å vise menyen
Oppgave
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
forloop 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
sumafter the loop ends.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 22
single