-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringpalin_3.java
More file actions
55 lines (44 loc) · 1.04 KB
/
stringpalin_3.java
File metadata and controls
55 lines (44 loc) · 1.04 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Java program to check whether a
// string is a Palindrome
// Using two pointing variables
// Main class
import java.util.*;
public class stringpalin_3 {
// Method
// Returning true if string is palindrome
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
// Method 2
// main driver method
public static void main(String[] args)
{
// Input string
Scanner sc=new Scanner(System.in);
String str = sc.nextLine();
// Convert the string to lowercase
str = str.toLowerCase();
// passing bool function till holding true
if (isPalindrome(str))
// It is a palindrome
System.out.print("Yes");
else
// Not a palindrome
System.out.print("No");
}
}