Create a collection HashMap<string, string="">, place 10 pairs of strings into the collection: watermelon - berry, banana - grass, cherry - berry, pear - fruit, melon - vegetable, blackberry - berry, ginseng - root, strawberry - berry, iris - flower, potato - tuber. Display to the screen the contents of the collection. Each entry should be on a new line.

Output example (only one string is shown): potato - tuber Works fine, but didn't passed. Any idea?

public class Solution

{

public static void main(String[] args) throws Exception
{
    Map<String, String> map = new HashMap<String, String>();
    map.put("watermelon", "berry");
    map.put("cherry", "berry");
    map.put("pear", "fruit");
    map.put("melon", "vegetable");
    map.put("blackberry", "berry");
    map.put("ginseng", "root");
    map.put("strawberry", "berry");
    map.put("iris", "flower");
    map.put("potato", "tuber");

    for (Map.Entry<String, String> pair : map.entrySet())
    {
        String key = pair.getKey();
        String value = pair.getValue();
        System.out.println(key + " - " + value);
    }
}

}

asked 02 Sep, 09:01

Demotivator's gravatar image

Demotivator
11
accept rate: 0%

edited 02 Sep, 09:02

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×19

Asked: 02 Sep, 09:01

Seen: 21 times

Last updated: 02 Sep, 09:02