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

📄 checkpalindrome.java

📁 JAVA程序设计导论那本书上的一些源代码. 在学那本书的下来的
💻 JAVA
字号:
import javax.swing.JOptionPane;public class CheckPalindrome {  /** Main method */  public static void main(String[] args) {    // Prompt the user to enter a string    String s = JOptionPane.showInputDialog(null,      "Enter a string:", "Example 7.1 Input",      JOptionPane.QUESTION_MESSAGE);    // Declare and initialize output string    String output = "";    if (isPalindrome(s))      output = s + " is a palindrome";    else      output = s + " is not a palindrome";    // Display the result    JOptionPane.showMessageDialog(null, output,      "Example 7.1 Output", JOptionPane.INFORMATION_MESSAGE);  }  /** Check if a string is a palindrome */  public static boolean isPalindrome(String s) {    // The index of the first character in the string    int low = 0;    // The index of the last character in the string    int high = s.length() - 1;    while (low < high) {      if (s.charAt(low) != s.charAt(high))        return false; // Not a palindrome      low++;      high--;    }    return true; // The string is a palindrome  }}

⌨️ 快捷键说明

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