- import java.util.Scanner;
- public class palindrom
- {
- public static boolean isPal(String s)
- {
- if(s.length() == 0 || s.length() == 1)
- return true;
- if(s.charAt(0) == s.charAt(s.length()-1))
- return isPal(s.substring(1, s.length()-1));
- return false;
- }
- public static void main(String[]args)
- {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Input yang mau di check:");
- String string = scanner.nextLine();
- if(isPal(string))
- System.out.println(string + " Palindrom");
- else
- System.out.println(string + " Bukan Palindrom");
- }
- }
0 comments:
Post a Comment