判断是否为回文

    技术2022-05-11  71

    import javax.swing.JOptionPane;//JOptionPane的YES_NO_OPTION怎么改变聚焦?

    public class palindrome {public static void main(String a[])  {while(true)   {   String pa=JOptionPane.showInputDialog("Please input the string:");   int half_pa=pa.length()/2;    int i=half_pa;          while(pa.charAt(i)==pa.charAt(pa.length()-i-1)&&i!=0)       {       i--;       };      if(i==0)       {        int answer = JOptionPane.showConfirmDialog(null, "This string is palindrome./nEnd program?", "Result.", JOptionPane.YES_NO_OPTION);          if (answer == JOptionPane.YES_OPTION)          System.exit(0);          else if (answer == JOptionPane.NO_OPTION)          System.out.println("/nOne more time");       }       else       {        int answer = JOptionPane.showConfirmDialog(null,"This string is not palindrome./nEnd program?","Result.",JOptionPane.YES_NO_OPTION);        if (answer == JOptionPane.YES_OPTION)          System.exit(0);          else if (answer == JOptionPane.NO_OPTION)          System.out.println("/nOne more time");        }    } }  }
     

    最新回复(0)