回文数
来源:互联网 发布:怎么做淘宝图片 编辑:程序博客网 时间:2024/04/20 04:08
利用栈的思想判断回文数:
public static void main(String[] args) { // TODO Auto-generated method stub int a[]={'a','b','c','c','b','a'}; int b[]=new int[3]; int top=0; int mid=a.length/2; for(int i=0;i<mid;i++) b[top++]=a[i]; for(int m=mid;m<a.length;m++){ if(b[top-1]!=a[m]) break; top--; } if(top==0) System.out.println("yes"); else System.out.println("no"); }
0 0