Java - error: incompatible types: Long cannot be converted to String [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 hours ago.
Improve this questionWhen I run the below code, I am getting ./Solution.java:13: error: incompatible types: Long cannot be converted to String
error. I am not able to understand why.
public class Solution {
public Long solve(Long A, int B) {
String binaryStr = "";
while(true) {
if(A > 6) {
binaryStr = String.valueOf((A % 2)) + binaryStr;
} else {
binaryStr = "0" + binaryStr;
}
A = Math.floor(Integer.parseInt(A) / 2);
if(A == 0) {
break;
}
}
return binaryStr;
}
}
Somebody help me fix this problem.
Thanks in advance.
精彩评论