Share your repls and programming experiences

← Back to all posts
Palindrome string program in java using scanner
RaghunathThilag (1)

Palindrome string program in java using scanner. Learn how to write a program to print palindrome or not in java using letters. In the Java programming language, you can make a palindrome or not. The topic of this program is whether or not the word is a palindrome. Madam,malayalam. maam is a title, phrase, or sequence that reads the same backwards as forwards.

import java.util.*;

class Main
{
public static void main(String args[])
{
String a, b = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter the string");
a = in.nextLine();
int length = a.length();
for (int i = length - 1; i >= 0; i--)
b = b + a.charAt(i);
if(a.equals(b))
System.out.println("The string is a palindrome.");
else
System.out.println("The string is not a palindrome.");
}
}

Enter a string

maam

the string is a palindrome

Link: https://inlarn.com/palindrome-string-program-in-java-using-scanner/