-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckStringPalindrome.java
More file actions
51 lines (43 loc) · 1.04 KB
/
Copy pathCheckStringPalindrome.java
File metadata and controls
51 lines (43 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
/*
47. How to check if String is Palindrome?
Another easy coding question based upon String, I am sure you must have done this numerous time.
Your program should return true if String is a Palindrome, otherwise false. For example, if the input
is "radar", the output should be true, if the input is "madam" output will be true, and if the input
is "Java" output should be false.
*/
import java.util.*;
public class CheckStringPalindrome
{
public static void main(String x[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String ");
String s=sc.nextLine();
String str=new String();
for(int i=0; i<s.length(); i++)
{
str=str+s.charAt(s.length()-1-i);
}
boolean flag=false;
for(int i=0; i<s.length(); i++)
{
if(s.charAt(i)==str.charAt(i))
{
flag=true;
}
else
{
flag=false;
break;
}
}
if(flag)
{
System.out.println("String is Palindrome ");
}
else
{
System.out.println("String is Not Palindrome ");
}
}
}