开发者

help with convert in java for android [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the开发者_如何学JAVA help center. Closed 11 years ago.

I have this code in C#, I have tried to convert him to Java for android, but I get an error in doing so.

This is the C# code:

sum = "";
string Num = "123ABC";
int i, j;
string TmpOT;
for (i = 0; i < Num.Length; i++)
{
    TmpOT = Num.Substring(i, 1);
    j = Convert.ToChar(TmpOT);
    j = (j / 10) + (j % 10);
    if (j >= 10)
    {
        j = (j / 10) + (j % 10);
    }
    sum += j.ToString();
}

And this my attempt at converting it to Java:

for (i = 0; i < Num.length(); i++)
{
    TmpOT = Num.substring(i, 1);
    j = Convert.ToChar(TmpOT);
    j = (j / 10) + (j % 10);
    if (j >= 10)
    {
        j = (j / 10) + (j % 10);-
    }
    Sum += String.valueOf(j);
}

the error is in line 5 - convert to char


There is no such thing as Convert.ToChar(...) in Java. You need to find the correct method.


The first method in the java method listing for the String class: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#charAt(int)


Instead of the Java Convert.ToChar(TmpOT) try (int)TmpOT as Convert.ToChar(...) does not exist in Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜