If statement 做决定时不需要陈述
我想把这段代码转换成另一段没有switch或if语句的代码 需要帮忙吗 这是一个面试问题If statement 做决定时不需要陈述,if-statement,If Statement,我想把这段代码转换成另一段没有switch或if语句的代码 需要帮忙吗 这是一个面试问题 if(x==9) return "3"; if (x==3) return "9"; else return "not valid"; 其中x是用户输入的词典 private static readonly Values=newdictionary{{3=>“9”,9=>“3”}; //用法 var值=10;//用户输入 返回值.getValue
if(x==9)
return "3";
if (x==3)
return "9";
else
return "not valid";
其中x是用户输入的词典
private static readonly Values=newdictionary{{3=>“9”,9=>“3”};
//用法
var值=10;//用户输入
返回值.getValuerDeafult(值“无效”);
您考虑过三元结构吗
String result = x == 9 ? "3" : "not valid";
result = x == 3 ? "9" : result;
return result;
Map<Integer, String> map = new HashMap<>();
map.put(9, "3");
map.put(3, "9");
String result = map.get(x);
return result == null ? "not valid" : result;
还是一张三元地图
String result = x == 9 ? "3" : "not valid";
result = x == 3 ? "9" : result;
return result;
Map<Integer, String> map = new HashMap<>();
map.put(9, "3");
map.put(3, "9");
String result = map.get(x);
return result == null ? "not valid" : result;
Map Map=newhashmap();
图.put(9,“3”);
图.put(3,“9”);
字符串结果=map.get(x);
返回结果==null?“无效”:结果;
求职面试问题?也许应该进行更多的研究,而不是问答案。@S3DEV如果你能帮得上忙的话。和我一起搜索答案会有帮助,因为我找不到这个问题的答案,这就是我为什么要问这个问题的原因!