我想打印相应的字符串值,使用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)
2条答案
按热度按时间nhhxz33t1#
尝试导入它:
py49o6xq2#
你可以检查导入并尝试
除此之外我没看到什么奇怪的