prg-lang-2 / week12 / ExerR07.java
ExerR07.java
Raw
// レポート課題07 回文
/*
#include <stdio.h>

#define LEN 256

int main(void) {
    char str[LEN]; // 文字列を格納する配列
    int kaibun; // 回文なら 1 そうでなければ 0

    // 文字列の入力
    scanf("%s", str);

    // 回文チェック ここから

    // ここまで

    printf("%s is ", str);
    if ( !(kaibun) ) {
        printf("not ");
    }
    printf(" Kaibun.\n");

    return 0;
}
*/
import java.util.*;

public class ExerR07 {
    public static void main(String[] args) {
        String str; // 文字列を格納する
        boolean kaibun = true; // 回文なら true そうでなければ false

        // 文字列の入力
        Scanner scanner = new Scanner(System.in);
        str = scanner.nextLine();
        scanner.close();

        // 回文チェック ここから

        int len = str.length();
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) != str.charAt(len - 1 - i)) {
                kaibun = false;
                break;
            }
        }

        // ここまで

        System.out.printf("%s is ", str);
        if (!kaibun) {
            System.out.printf("not ");
        }
        System.out.printf("Kaibun.\n");
    }
}