Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Filtering Numbers in a Loop | Loops
Java Basics
course content

Kurssisisältö

Java Basics

Java Basics

1. Getting Started
2. Basic Types and Operations
3. Loops
4. Arrays
5. String

book
Challenge: Filtering Numbers in a Loop

Tehtävä

Swipe to start coding

Find the sum of all numbers from 1 to n, excluding those that are divisible by 3 or 5.

  1. Create a method called sumNotDivisibleBy3Or5(int n) that returns an int.
  2. Inside this method, create a for loop that iterates from 1 to n (inclusive).
  3. In each iteration, check if the number is not divisible by 3 and not divisible by 5.
  4. If the number passes the condition, add it to a running total sum.
  5. Return the total sum after the loop ends.

Ratkaisu

java

solution

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 8
toggle bottom row

book
Challenge: Filtering Numbers in a Loop

Tehtävä

Swipe to start coding

Find the sum of all numbers from 1 to n, excluding those that are divisible by 3 or 5.

  1. Create a method called sumNotDivisibleBy3Or5(int n) that returns an int.
  2. Inside this method, create a for loop that iterates from 1 to n (inclusive).
  3. In each iteration, check if the number is not divisible by 3 and not divisible by 5.
  4. If the number passes the condition, add it to a running total sum.
  5. Return the total sum after the loop ends.

Ratkaisu

java

solution

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 8
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt