用java输出0-99999之间的三重回文数

付睿 2015-10-20 02:07:22
ps:只能显示出11然后就直接强退了。
import javax.swing.JOptionPane;

public class ProjectThree {
public static int Reverse(int x1){
int reverse = 0;
int[] m = new int[6];
int i = 0;
while (x1 != 0) {
i++;
m[i] = x1%10;
x1 = x1/10;
}
int j = i;
for(;i>=1;i--){
reverse += m[i]*Math.pow(10, j - i);
}
return reverse;
}
public static boolean IsPalindrome(int x1){
int num2 = Reverse(x1);
if (x1 == num2)
return true;
else
return false;
}
public static void main(String[]args){
for(int x=10;x<=99999;x++){
int x1 = (int) Math.pow(x, 2);
int x2 = (int) Math.pow(x, 3);
if(IsPalindrome(x)==true&&IsPalindrome(x1)==true&&IsPalindrome(x2)==true)
JOptionPane.showMessageDialog(null, x);
}
}

}
...全文
283 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
付睿 2015-10-20
  • 打赏
  • 举报
回复
谢谢你了,亲。
ITjavaman 2015-10-20
  • 打赏
  • 举报
回复
public static boolean IsPalindrome(int x1){ String s = Integer.toString(x1); StringBuffer sb = new StringBuffer(s); if(s.equals(sb.reverse().toString())){ return true; }else{ return false; } } public static void main(String[]args){ for(int x=10;x<=99999;x++){ int x1 = (int) Math.pow(x, 2); int x2 = (int) Math.pow(x, 3); if(IsPalindrome(x)==true&&IsPalindrome(x1)==true&&IsPalindrome(x2)==true) JOptionPane.showMessageDialog(null, x); // System.out.println(x); } } 根据你的需要修改了一下

50,639

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧