-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCheck Palindrome
More file actions
33 lines (30 loc) · 894 Bytes
/
Check Palindrome
File metadata and controls
33 lines (30 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
class palindrome {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("Enter a string as an input to check whether it is palindrome or not");
String input= scanner.nextLine();
//checking whether palindrome or not
if(isPalindrome(input))
{
System.out.println(input+" is a palindrome string");
}
else
{
System.out.println(input+" is not a palindrome string");
}
}
public static boolean isPalindrome(String str) {
int left = 0, right = str.length() - 1;
while(left < right)
{
if(str.charAt(left) != str.charAt(right))
{
return false;
}
left++;
right--;
}
return true;
}
}