java小程序之判断回文数

来源:互联网 发布:加大usb口电流软件 编辑:程序博客网 时间:2024/04/29 16:48

import java.applet.*;
import java.awt.*;
import javax.swing.JOptionPane;

public class panduanwenhunshu {
        public static void main(String args[]){
         String s1;
         int x,i=0,k=0;
         int a = 0;
         int [] str=new int[30];
         String output1="请输入一个数字:";
         String output2="这个数不是回文数!";
         String output3="这个数是回文数!";
         JOptionPane.showMessageDialog(null,output1,"判断回文数:",JOptionPane.INFORMATION_MESSAGE);
         s1=JOptionPane.showInputDialog(null,"请输入回文数:","判断回文数:",javax.swing.JOptionPane.QUESTION_MESSAGE);
         x=Integer.parseInt(s1);
         while(x>0){
          str[k++]=x%10+'0';
          x=x/10;
         }
         for(i=0;i<=k/2;i++){
         if(str[i]!=str[k-i-1])
         {
          a=0;
           break;
           }
           else
           a=1;
              
         }
         
         if(a==1)
             JOptionPane.showMessageDialog(null,output3,"判断回文数:",JOptionPane.INFORMATION_MESSAGE);
         else
        
          JOptionPane.showMessageDialog(null,output2,"判断回文数:",JOptionPane.INFORMATION_MESSAGE);
       
        } 
 
}

原创粉丝点击