- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个5位数");
- int i=sc.nextInt();
- String str=i+"";
-
- char arr[]=str.toCharArray();
- System.out.println(panDuanHuiWen(arr));
- }
- public static boolean panDuanHuiWen(char x[])
- {
- boolean flag=false;
- int i=0;
- while(i<=x.length/2+1)
- {
- if (x[i]!=x[x.length-i-1])
- {
- flag=false;
- break;
- }
- else
- {
- flag=true;
- i++;
- }
- }
- return flag;
- }
复制代码
自己刚刚做好的,真是备儿有成就感! |
|