Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Inventory

Build an inventory tracker! Start with an empty HashMap, then:

  1. Add "apples" with quantity 5
  2. Add "bananas" with quantity 3
  3. Add "oranges" with quantity 7
  4. Update "apples" to quantity 10 (just insert again with the new value)

Print each item and its quantity in alphabetical order.

Expected output:

text
apples: 10
bananas: 3
oranges: 7

Hints:

  • Start with let mut inventory = HashMap::new();
  • Use .insert() to add items -- inserting the same key again updates the value
  • Collect keys, sort, and loop to print in order
rust
fn main() {
}