1// String palindrome in java without using reverse method
2import java.util.Scanner;
3public class StringPalindromeDemo
4{
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Please enter string to check palindrome: ");
9 String strInput = sc.nextLine();
10 // converting string to char array
11 char[] chString = strInput.toCharArray();
12 // storing reverse string
13 String strReverse = "";
14 // reading char by char
15 for(int a = chString.length - 1; a >= 0; a--)
16 {
17 strReverse = strReverse + chString[a];
18 }
19 // printing given string and reversed string
20 System.out.println("Given string: " + strInput);
21 System.out.println("Reverse String: " + strReverse);
22 // check if given string is palindrome
23 if(strInput.equals(strReverse))
24 {
25 System.out.println("string is palindrome.");
26 }
27 else
28 {
29 System.out.println("string is not palindrome.");
30 }
31 }
32}