help with convert in java for android [closed]
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.
精彩评论