Program will take input as str and Program will check the string is same from both direction.
Sample Input 1adda
Sample Output 1
true
Sample Input 2
akdm
Sample Output 2
false
Solution
import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc=new Scanner(System.in);
String str=sc.next();
System.out.println(palin(str));
}
public static boolean palin (String str)
{
int i=0;
int j=str.length()-1;
while(i<j)
{
if(str.charAt(i)!=str.charAt(j))
{
return false;
}
i++;
j--;
}
return true;
}
}