我试图转换整数到字符串由 “/” 或 “\”转换整数 “/ ” 串
例如建立:6 = /\
,22 = //\\\\
,其中/ = 1 \ = 5
当x = 1或x = 5是正确
public String fromArabic(int x)
{
if(x>29 || x<1)
throw new IllegalArgumentException("Error IllegalArgumentException");
int tmp=x;
String out="";
StringBuilder o=new StringBuilder(out);
while(tmp!=0)
{
if(tmp-5>=0)
{
tmp-=5;
o.append("\\");
}
else if(tmp-1>=0 && tmp-5<0)
{
tmp-=1;
o.append("/");
}
}
out=o.toString();
return out;
}
OUTPUT:
预期:< [// \\]>但是:< [\\ // //]>
如何使其正确?
为什么请'22 == // \\'? '5 + 5 + 1 + 1 == 12',而不是'22'? –
// \\(12) - 1 + 1 + 5 + 5 – vbv111