Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Array Sum Calculator | Applying Loops in Real Problems
Java Loops

bookChallenge: Array Sum Calculator

Tehtävä

Swipe to start coding

You are tasked with writing a simple program to help a cashier sum up the total price of items in a shopping cart, but only count items that cost more than $10. This will help the cashier quickly check high-value purchases.

Follow these steps:

  1. Complete the sumHighValueItems method, which takes an array of integers called prices representing item prices in dollars;
  2. Use a loop to go through each price in the array;
  3. For each price, use a conditional statement to check if the price is greater than 10;
  4. If the price is greater than 10, add it to a running total;
  5. After checking all prices, return the total sum of items costing more than $10.

Example input:

int[] prices = {5, 12, 8, 20, 3, 15}; => 47

Ratkaisu

solution.java

solution.java

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 3
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

Awesome!

Completion rate improved to 9.09

bookChallenge: Array Sum Calculator

Pyyhkäise näyttääksesi valikon

Tehtävä

Swipe to start coding

You are tasked with writing a simple program to help a cashier sum up the total price of items in a shopping cart, but only count items that cost more than $10. This will help the cashier quickly check high-value purchases.

Follow these steps:

  1. Complete the sumHighValueItems method, which takes an array of integers called prices representing item prices in dollars;
  2. Use a loop to go through each price in the array;
  3. For each price, use a conditional statement to check if the price is greater than 10;
  4. If the price is greater than 10, add it to a running total;
  5. After checking all prices, return the total sum of items costing more than $10.

Example input:

int[] prices = {5, 12, 8, 20, 3, 15}; => 47

Ratkaisu

solution.java

solution.java

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 3
single

single

some-alt