-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstring_palindrome.java
More file actions
36 lines (34 loc) · 906 Bytes
/
string_palindrome.java
File metadata and controls
36 lines (34 loc) · 906 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
34
35
36
import java.util.Scanner;
public class string_palindrome
{//palindrome of a word
String str;
int len;
void input()
{
Scanner sc= new Scanner(System.in) ;
System.out. println("enter a word");
str=sc.next();
len=str.length();
}
void palindrome()
{
String reverse="";
char ch;
for(int i=len-1;i>=0;i--)
{
ch=str.charAt(i);
reverse =reverse+ch;
}//end of for
System.out.println("reversed "+reverse);
if(reverse.equals(str))
System.out.println(str+" is a palindrome string");
else
System.out.println(str+" is NOT a palindrome string");
}
public static void main(String args[])
{
string_palindrome obj = new string_palindrome();
obj.input();
obj.palindrome();
}
}