我想这样做Clojure中:如何在Clojure中的函数内部有多个if语句?
int i=1;j=2;k=3;
str r;
cin>>r;
if(r=="A")
cout<<i; (i.e., print 1)
if(r=="J")
cout<<j; (i.e., print 2)
if(r=="K")
cout<<k; (i.e., print 3)
else
do something else
我做它像这样用Clojure:
(defn str-to-num [c]
(if (= (str (first c)) "A")
1
(java.lang.Integer/valueOf (str (first c))))
(if (= (str (first c)) "J")
2
(java.lang.Integer/valueOf (str (first c))))
(if (= (str (first c)) "K")
3
(java.lang.Integer/valueOf (str (first c))))
)
但是,我发现了一个错误。有人可以告诉我做错了什么吗?
什么是错误您收到? – munk 2014-10-17 02:23:45
NumberFormatException对于输入字符串:“A”java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) – 2014-10-17 02:26:51
如果我只有一条if语句,只说:(if(=(str(first c))“A”) (java.lang.Integer/valueOf(str(first c)))) 然后它工作正常。发生了什么? – 2014-10-17 02:27:32