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

📄 stringandcomments.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:
/** This is a test program to test the methods <code>reverseString</code>
    and <code>removeLeadingChars</code>.
    @author B G. W
    @version 2003/03/10
 */
public class StringAndComments {
   /** This method reverses the input string, i.e. the input string is
          returned character by character in reverse order.
          @return String
    */
   public static String reverseString(String s) {
      String reverseS = "";
      for (int i = s.length() - 1; i >= 0; i--) {
         reverseS += s.charAt(i);
      }
      return reverseS;
   }

   /** This method removes all leading characters from the input
       string s. The character to be removed is determined by
       the input parameter <code>removeThis</code>
       @return String
    */
   public static String removeLeadingChars(String s, char removeThis) {
      while ( (s.length() > 0) && (s.charAt(0) == removeThis)) {
         s = s.substring(1, s.length());
      }
      return s;
   }

   /** The main method tests <code>removeLeadingChars</code> and
       <code>reverseString</code> to see if they work correctly.
       @see StringAndComments#removeLeadingChars(String, char)
       @see StringAndComments#reverseString(String)
    */
   public static void main(String args[]) {
      String s = "# Otto";
      String uncommented = removeLeadingChars(s, '#');
      String upper = reverseString(uncommented).toUpperCase();
      if (s.toUpperCase().equals(upper)) {
         System.out.println("String is a palindrome");
      }
   }
}

⌨️ 快捷键说明

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