PhysicsTeacher.in

High School Physics + more

Palindrome Program in Java using String methods

Here is a Java program that is written as a Palindrome Program in Java using String methods. This program allows the user to enter a string/number. Then the program checks whether the input is a Palindrome or not, and then responds back accordingly.

This program is useful for students who are learning Java (or BlueJ). Students of ICSE, CBSE, and state boards of India will find it useful.

Java Program for Palindrome checking (using String methods)

//Palindrome Program in Java using String methods

import java.util.*;
class PalindromeExample


{
public static void main(String args[])
{
String original, reverse = “”; // Objects of String class
Scanner in = new Scanner(System.in);
System.out.println(“Enter a string/number to check if it is a palindrome”);
original = in.nextLine();
int length = original.length();


for ( int i = length – 1; i >= 0; i– )
reverse = reverse + original.charAt(i);


if (original.equals(reverse))
System.out.println(“Entered string/number is a palindrome.”);
else
System.out.println(“Entered string/number isn’t a palindrome.”);

}

}

See also  simple Java program using constructor
Scroll to top
error: physicsTeacher.in