Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Map<Integer, Integer> data = new HashMap<Integer, Integer>();
        data.put(10, 2);
        data.put(20, 3);
        data.put(30, 5);
        data.put(40, 15);
        data.put(50, 4);

        SortedSet<Integer> keys = new TreeSet<Integer>(data.keySet());
        String s = "";
        for (Integer key : keys) {
            s += key + " : ";
            for (int i = 0; i < data.get(key); i++) {
                s += "*";
            }
            s += "\n";
        }
        System.out.println(s);
    }
}