⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 palindrome.java

📁 回文数的判断
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
public class Palindrome
{
   public static void main(String args[])
   {
      MyFrame f=new MyFrame();
      f.setTitle("回文数的判断:");
      f.setBounds(12,12,300,300);
      f.setVisible(true);
      f.validate();
      f.addWindowListener(new WindowAdapter()
         {
            public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         }          
      );
   }
}
class MyFrame extends Frame implements ActionListener
{
  TextField output;
  TextArea  text;
  Button  b;
  public MyFrame()
  {  text=new TextArea();
     output=new TextField(10);
     Panel pNorth=new Panel(),pSouth=new Panel();
     pNorth.add(new Label("请输入要check的字符串:"));
     pSouth.add(new Label("检测结果是:"));
     pSouth.add(output);
     b=new Button("确定");
     b.addActionListener(this);
     pSouth.add(b);
     add(text,BorderLayout.CENTER);
     add(pNorth,BorderLayout.NORTH);
     add(pSouth,BorderLayout.SOUTH);
  
  } 
  String qubiaodian(String s)
  {
   char [] chs = s.toCharArray();String temp="";
   for(int i=0;i<chs.length;i++)
   {
    if(Character.isDigit(chs[i])==true || Character.isLetter(chs[i])==true)
    {
       temp+=s.charAt(i);
    }
  
   }
   return temp;
    
  }
  public void actionPerformed(ActionEvent e)
  { 
     String str;
     str=text.getText();
     if(e.getSource()==b)
     {
        String temp="",str1,str2,str3;
        str1=qubiaodian(str);
        str2=str1.toLowerCase();
        str3=str2.replaceAll(" ","");
        boolean flag=false;
        for(int i=str3.length()-1;i>=0;i--)
        {
           temp+=str3.charAt(i);
        }
        if(temp.equals(str3))
        {
             flag=true;
        }
        if(flag) 
           output.setText("是回文数");
        else  
           output.setText("不是回文");
        
   

     }
     
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -