我的代码不起作用。这是我程序的初始部分。当我尝试反转字符串时发生主要错误。有人可以看看吗?
我必须反转字符串才能将二进制数转换为十进制数。
String checka, checkb;
checka = txt1.getText();
checkb = txt2.getText();
int lchecka = checka.length();
int lcheckb = checkb.length();
int ia, ib, p = 1, q = 1;
for (ia = 0; ia < lchecka; ia++)
{
if (checka.charAt(ia) == '1' || checka.charAt(ia) == '0')
{
p = 1;
}
else
{
p = 0;
break;
}
}
for (ib = 0; ib < lcheckb; ib++)
{
if (checkb.charAt(ib) == '1' || checkb.charAt(ib) == '0')
{
q = 1;
}
else
{
q = 0;
break;
}
}
double adda = 0, addb = 0, ansa = 0, ansb = 0;
int inta, intb;
inta = Integer.parseInt(txt1.getText());
intb = Integer.parseInt(txt2.getText());
if (p == 1 && q == 1)
{
String checkka;
checkka = txt1.getText();
String checkkb;
checkkb = txt2.getText();
int lcheckka = checkka.length();
int lcheckkb = checkkb.length();
Character oa, ob;
int ra, rb;
String reva, revb;
oa = checkka.charAt(lcheckka - 1);
reva = oa + "";
ob = checkkb.charAt(lcheckkb - 1);
revb = ob + "";
oa = checkka.charAt(lcheckka - 2);
reva = reva.substring(0) + oa;
ob = checkkb.charAt(lcheckkb - 2);
revb = revb.substring(0) + ob;
for (ra = lcheckka - 3; ra >= 0; ra--)
{
oa = checkka.charAt(ra);
reva = reva.substring(0, ra - 1) + oa;
}
for (rb = lcheckkb - 3; rb >= 0; rb--)
{
ob = checkkb.charAt(rb);
revb = revb.substring(0, rb - 1) + ob;
}
System.out.println(reva);
System.out.println(revb);
}