java正在尝试查找回文数
我试图找到回文“否”,但每次都显示“否”为假,即使是“121” 请帮忙
public boolean isPalindrome(int x) {
if(x<0 || x%10==0){
return false;
}
int rev = 0;
while(x!=0){
rev=(rev*10)+(x%10);
x/=10;
}
if(x==rev){
return true;
}
else{
return false;
}
}
# 1 楼答案
希望这是有用的:
# 2 楼答案
你的功能可以像下面这样简单
# 3 楼答案
你所需要做的就是在减少原有数量的同时建立新的数量。然后比较两者
印刷品
# 4 楼答案
作为一个选项,您可以创建如下内容:
# 5 楼答案
因为在while循环结束后,
x will be 0
,您必须对副本执行操作