Palindrome in Java

How Can We Help?

Table of Contents

Compile and Run the following code with Command-Prompt Or download Notepad++

For Compilation javac

For Execution java Sample

import java.util.Scanner;
class Sample
  public static void main(String args[])
    String a,b;
    StringBuffer sb;
    Scanner sc = new Scanner(;
    System.out.println("Enter the string to be checked: ");
    a = sc.nextLine();
    sb = new StringBuffer(a);
    b = sb.reverse().toString();
      System.out.println("Entered String is a Palindrome");
      System.out.println("Entered String is not a Palindrome");

Leave a Reply