From 414a649d0247cd50ec79228645fddbe858862b8b Mon Sep 17 00:00:00 2001 From: JunkJumper Date: Wed, 2 Sep 2020 14:34:03 +0200 Subject: [PATCH] exo 2 ok --- src/TP1/Palindrome.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/TP1/Palindrome.java diff --git a/src/TP1/Palindrome.java b/src/TP1/Palindrome.java new file mode 100644 index 0000000..771ac38 --- /dev/null +++ b/src/TP1/Palindrome.java @@ -0,0 +1,28 @@ +package TP1; + +import java.util.Scanner; + +public class Palindrome { + + public static String lire() { + String s; + Scanner sc = new Scanner(System.in); + s = sc.nextLine(); + sc.close(); + return s; + } + + public static boolean pal(String s) { + if(s.length() == 0 || s.length() == 1) { + return true; + } else if(s.charAt(0) == s.charAt(s.length()-1)) { + return pal(s.substring(1, s.length()-2)); + } else { + return false; + } + } + + public static void main(String[] args) { + System.out.println(pal(lire())); + } +}