<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # java 程序:使用遞歸檢查回文字符串 > 原文: [https://beginnersbook.com/2014/01/java-program-to-check-palindrome-string-using-recursion/](https://beginnersbook.com/2014/01/java-program-to-check-palindrome-string-using-recursion/) **程序:使用遞歸檢查`String`是否為回文** ```java package beginnersbook.com; import java.util.Scanner; class PalindromeCheck { //My Method to check public static boolean isPal(String s) { // if length is 0 or 1 then String is palindrome if(s.length() == 0 || s.length() == 1) return true; if(s.charAt(0) == s.charAt(s.length()-1)) /* check for first and last char of String: * if they are same then do the same thing for a substring * with first and last char removed. and carry on this * until you string completes or condition fails * Function calling itself: Recursion */ return isPal(s.substring(1, s.length()-1)); /* If program control reaches to this statement it means * the String is not palindrome hence return false. */ return false; } public static void main(String[]args) { //For capturing user input Scanner scanner = new Scanner(System.in); System.out.println("Enter the String for check:"); String string = scanner.nextLine(); /* If function returns true then the string is * palindrome else not */ if(isPal(string)) System.out.println(string + " is a palindrome"); else System.out.println(string + " is not a palindrome"); } } ``` 輸出: ```java Enter the String for check: qqaabb qqaabb is not a palindrome ``` 輸出 2: ```java Enter the String for check: cocoococ cocoococ is a palindrome ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看