Program demonstrating simple Palindrome test for a string through a simple Java code.
Video tutorial to demonstrate how to check whether a given string is palindrome or not through a Java program.
package com.hubberspot.string.example; import java.util.Scanner; public class PalindromeTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a string to test : "); String string = input.nextLine(); if (palindromeCheck(string)) System.out.println(string + " is a palindrome"); else System.out.println(string + " is not a palindrome"); } public static boolean palindromeCheck(String string) { int low = 0; int high = string.length() - 1; while (low < high) { if (string.charAt(low) != string.charAt(high)) return false; low++; high--; } return true; } }Output of the program :
Video tutorial to demonstrate how to check whether a given string is palindrome or not through a Java program.