Challenge: Array Sum Calculator
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:
- Complete the
sumHighValueItemsmethod, which takes an array of integers calledpricesrepresenting item prices in dollars; - Use a loop to go through each price in the array;
- For each price, use a conditional statement to check if the price is greater than 10;
- If the price is greater than 10, add it to a running total;
- 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
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 9.09
Challenge: Array Sum Calculator
Pyyhkäise näyttääksesi valikon
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:
- Complete the
sumHighValueItemsmethod, which takes an array of integers calledpricesrepresenting item prices in dollars; - Use a loop to go through each price in the array;
- For each price, use a conditional statement to check if the price is greater than 10;
- If the price is greater than 10, add it to a running total;
- 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
Kiitos palautteestasi!
single