无法解析为Java中的类型

stszievb  于 2022-12-17  发布在  Java
关注(0)|答案(2)|浏览(167)

我想打印相应的字符串值,使用java中的颜色代码查找电感或电感器

public class Inductance
{
 
  // Function to find the inductance
  // using color codes of inductor
  public static void findInductance(String a, String b, String c, String d)
  {
 
    // Hash-map to store the values
    // of the color-digits
    HashMap<String, String> color_digit = new HashMap<String, String>() ;
    color_digit.put("black", "0");
    color_digit.put("brown", "1");
    color_digit.put("red", "2");
    color_digit.put("orange", "3");
    color_digit.put("yellow", "4");
    color_digit.put("green", "5");
    color_digit.put("blue", "6");
    color_digit.put("violet", "7");
    color_digit.put("grey", "8");
    color_digit.put("white", "9");
 

    if (color_digit.containsKey(a)
        && color_digit.containsKey(b)
        && multiplier.containsKey(c)
        && tolerance.containsKey(d))
    {
      String xx = color_digit.get(a);
      String yy = color_digit.get(b);
      String zz = multiplier.get(c);
      String aa = tolerance.get(d);
      System.out.println("Inductance = " + xx + yy+
                         " x " + zz + " ohms " +  aa);
    }
    else
      System.out.println("Invalid Colors");
  }
 
  // Driver Code
  public static void main(String[] args)
  {
    String a = "black";
    String b = "brown";
    String c = "red";
    String d = "green";
 
    // Function Call
    findInductance(a, b, c, d);
  }
}

字符串
例如,色带是黑色,棕色和红色,电感应该是102,等等(Ps.我也添加了乘数和容差散列表,但网站说代码太长了,sooo)

nhhxz33t

nhhxz33t1#

尝试导入它:

import java.util.HashMap;
py49o6xq

py49o6xq2#

你可以检查导入并尝试

Map<String, String> color_digits = new HashMap<String, String>();

除此之外我没看到什么奇怪的

相关问题