開発メモ

開発用のメモです。

回文判定をする。

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        try (
            InputStreamReader ir = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(ir)
            ) 
        {
            String line= null;
            while ((line = in.readLine()) != null) {
                System.out.println();
                System.out.println("TARGET:" + line);
                if (line.length() < 2) {
                    System.out.println("LENGTH ERROR");
                    continue;
                }
                StringBuffer b1 = new StringBuffer(line);
                StringBuffer b2 = new StringBuffer(line);
                b2.reverse();
                if (Objects.equals(b1.toString(), b2.toString())) {
                    System.out.printf("%2d %n", line.length());
                }
            }
        }
    }
}
Twitter: @asahina_alice