id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

tmhscs@gmail.com welcomeback > welcomeback_map_toString
prev  |  next  |  chance

Given a String array of items and an integer array of quantities, create a TreeMap that uses Strings for keys and integers for values that contains all of the arrays contents, and then return map.toString(). The TreeMap will automatically sort the keys alphabetically and the toString method will automatically generate the necessary curly braces, commas, and equals signs. Your first line of code should be:

Map<String, Integer> map = new TreeMap<String, Integer>();

welcomeback_map_toString(["apples", "bananas"], [3, 5]) → "{apples=3, bananas=5}"
welcomeback_map_toString(["oranges", "grapes", "potatoes"], [5, 1, 4]) → "{grapes=1, oranges=5, potatoes=4}"
welcomeback_map_toString(["apples", "grapes", "bananas"], [3, 2, 5]) → "{apples=3, bananas=5, grapes=2}"

...Save, Compile, Run (ctrl-enter)

public String welcomeback_map_toString(String[] items, int[] quantities) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy