0

このダイの面から文字へのマッピングを返します。顔は 1 ~ 6 の整数値を使用して識別され、返されたマップはそのキー (顔番号) で並べ替えられます。たとえば、顔のあるサイコロ:

1、2、3、4、5、6

文字を持っている:

C、M、I、O、U、T

toString メソッドが次の文字列を生成するマップを返します。

{1=C, 2=M, 3=I, 4=O, 5=U, 6=T}

これは私がこれまでに持っているものですが、それが機能するとは思わず、エラーが発生しています:

public SortedMap<Integer, String> getValueMap() {
    
    SortedMap<Integer,String> sm=new TreeMap<Integer, String>();
       
        sm.put(new Integer(1), "A");
        sm.put(new Integer(2), "A");
        sm.put(new Integer(4), "E");
        sm.put(new Integer(3), "E");
        sm.put(new Integer(5), "G");
        sm.put(new Integer(6), "N");
        Set s=sm.entrySet();

        Iterator i=s.iterator();

        while(i.hasNext())
        {
            Map.Entry m =(Map.Entry)i.next();
            int key = (Integer)m.getKey();
            String sValue=(String)m.getValue();
            
        }
        return "Key :"+key+"  value :"+sValue;
}
4

0 に答える 0