Java 正在尝试在另一个方法中显示hashmap键集的列表

Java 正在尝试在另一个方法中显示hashmap键集的列表,java,class,hashmap,Java,Class,Hashmap,所以,我想从主类调用hashmap键集列表,并在控制台中列出它们。我试图在每次打印前显示按键集: public static void main(String[] args) { Scanner input = new Scanner(System.in); // The keyset can be set here to show the alternatives to convert to the user System.out.println("What le

所以,我想从主类调用hashmap键集列表,并在控制台中列出它们。我试图在每次打印前显示按键集:

public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
     // The keyset can be set here to show the alternatives to convert to the user
     System.out.println("What length you want to confert from");
     String to = input.nextLine();

     System.out.println("What length you want to confert to");
     String from = input.nextLine();

     System.out.println("Input length");
     double value = input.nextDouble();

     int result = (int)Length.convert(value, from, to);
     System.out.println((int )value +  from + " = " +  result + to);
}
** 以下是
Length
中用于转换长度的第二种方法: **

公共静态双转换(双值、字符串从、字符串到){
HashMap table=新的HashMap();
表1.put(“mm”,0.001);
表1.put(“厘米”,0.01);
表1.put(“dm”,0.1);
表1.put(“m”,1.0);
表1.put(“hm”,100.0);
表1.put(“km”,1000.0);
表1.put(英尺),0.3034;
表1.put(“yd”,0.9144);
表1.put(“mi”,1609.34);
double from_value=table.get(from);
double to_value=table.get(to);
双结果=从_值/到_值*值;
返回结果;
}

修复
长度
类:

class Length {

    //Declare the map as class variable
    static Map<String, Double> table = new HashMap<>();

    //Initialize the map
    static {
        table.put("mm", 0.001);
        table.put("cm", 0.01);
        table.put("dm", 0.1);
        table.put("m", 1.0);
        table.put("hm", 100.0);
        table.put("km", 1000.0);
        table.put("ft", 0.3034);
        table.put("yd", 0.9144);
        table.put("mi", 1609.34);
    }

    public static double convert(double value, String from, String to) {

        double from_value = table.get(from);
        double to_value = table.get(to);
        double result = from_value / to_value * value;

        return result;
    }

    //Print the KeySet
    public static void printMap() {
        System.out.println(table.keySet());
    }
}

你的问题到底是什么?
class Length {

    //Declare the map as class variable
    static Map<String, Double> table = new HashMap<>();

    //Initialize the map
    static {
        table.put("mm", 0.001);
        table.put("cm", 0.01);
        table.put("dm", 0.1);
        table.put("m", 1.0);
        table.put("hm", 100.0);
        table.put("km", 1000.0);
        table.put("ft", 0.3034);
        table.put("yd", 0.9144);
        table.put("mi", 1609.34);
    }

    public static double convert(double value, String from, String to) {

        double from_value = table.get(from);
        double to_value = table.get(to);
        double result = from_value / to_value * value;

        return result;
    }

    //Print the KeySet
    public static void printMap() {
        System.out.println(table.keySet());
    }
}
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    //Show Keyset
    Length.printMap();


    System.out.println("What length you want to confert from");
    String to = input.nextLine();

    System.out.println("What length you want to confert to");
    String from = input.nextLine();

    System.out.println("Input length");
    double value = input.nextDouble();

    int result = (int) Length.convert(value, from, to);
    System.out.println((int) value + from + " = " + result + to);
}