java - Trying to show the list of the hashmap keyset in the other method -


so, want call hashmap keyset list main class , list them in console. trying show keyset before each printing:

public static void main(string[] args) {      scanner input = new scanner(system.in);      // keyset can set here show alternatives convert user      system.out.println("what length want confert from");      string = input.nextline();       system.out.println("what length want confert to");      string = input.nextline();       system.out.println("input length");      double value = input.nextdouble();       int result = (int)length.convert(value, from, to);      system.out.println((int )value +  + " = " +  result + to); } 

** here second method in length converting length: **

public static double convert(double value, string from, string to){      hashmap<string, double> table= new hashmap<>();      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);       double from_value = table.get(from);      double to_value = table.get(to);      double result = from_value / to_value * value;       return result;   } 

fix length class :

class length {      //declare map class variable     static map<string, double> table = new hashmap<>();      //initialize 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 keyset     public static void printmap() {         system.out.println(table.keyset());     } } 

update main method :

public static void main(string[] args) {      scanner input = new scanner(system.in);      //show keyset     length.printmap();       system.out.println("what length want confert from");     string = input.nextline();      system.out.println("what length want confert to");     string = input.nextline();      system.out.println("input length");     double value = input.nextdouble();      int result = (int) length.convert(value, from, to);     system.out.println((int) value + + " = " + result + to); } 

Comments