-
Notifications
You must be signed in to change notification settings - Fork 2
/
palindrome.java
38 lines (37 loc) · 929 Bytes
/
palindrome.java
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
import java.util.*;
class userinput
{
public static void main(String args[])
{
Scanner myscanner=new Scanner(System.in);
System.out.println("Enter the name(Input # at the end):");
String str=myscanner.nextLine();
int length=0;
int flag=0;
for(int i=0;str.charAt(i)!='#';i++)
{
length=length+1;
}
System.out.println("The length is "+ length);
for(int i=0;i<=length/2;i++)
{
if(str.charAt(i)!=str.charAt(length-i-1))
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{
System.out.println("The name is a palindrome");
}
else
{
System.out.println("The name is not a palindrome");
}
}
}