Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fruit Prices

Create a HashMap with 3 fruits and their prices, then print each one. Use these fruits and prices:

  • "apple" costs 1.50
  • "banana" costs 0.75
  • "cherry" costs 2.00

Print them in alphabetical order, one per line, in the format fruit: $price.

Expected output:

text
apple: $1.5
banana: $0.75
cherry: $2

Hints:

  • Use HashMap::new() and .insert() to add entries
  • Collect the keys into a vector, sort it, then loop through the sorted keys
  • Use map[key] to look up the value for each key
rust
fn main() {
}