Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) { String or, re = ""; Scanner sc = new Scanner(System.in); System.out.print("Enter the string: "); or = sc.nextLine(); int length = or.length();
for (int i = length - 1; i >= 0; i--) { re = re + or.charAt(i); } if (or.equals(re)) { System.out.println("Entered string is Palindrome"); } else { System.out.println("Entered string is not Palindrome"); } }}
Output:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String or, re = "";
Scanner sc = new Scanner(System.in);
System.out.print("Enter the string: ");
or = sc.nextLine();
int length = or.length();
for (int i = length - 1; i >= 0; i--) {
re = re + or.charAt(i);
}
if (or.equals(re)) {
System.out.println("Entered string is Palindrome");
} else {
System.out.println("Entered string is not Palindrome");
}
}
}
Tags:
Java Programs