pal.java

来自「Java 入门书的源码」· Java 代码 · 共 23 行

JAVA
23
字号
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

// Debugging Exercise 6.8 -- Has Errors

        public class Pal {
          public static void main(String [] args) {
              int size = Io.readInt("How many characters?");
              char [] a = new char[size];
              for (int i=0; i<a.length; i++) 
              a[i] = Io.readChar("Enter next character");
              System.out.print("The word ");
              for (int i=0; i<a.length; i++)
                 System.out.print(a[i]);
              for (int i=1; i<a.length/2; i++) 
                 if (a[i] != a[a.length-i]) {
                    System.out.println(" is not a palindrome");
                    System.exit(0);
                 }
              System.out.println(" is a palindrome");
          }
      }

⌨️ 快捷键说明

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