-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPallin.java
74 lines (68 loc) · 1.46 KB
/
Pallin.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.Scanner;
class Pallin
{
public static void main(String[] args)
{
try
{
int a,rev=0,rem,choice;
String a1,b="";
char c;
int d=0,i;
Scanner sc=new Scanner(System.in);
System.out.println("Case:");
choice=sc.nextInt();
switch(choice)
{
case 1:
{
System.out.println("Enter the string:");
a1=sc.next();
d=a1.length();
for(i=d-1;i>=0;i--)
{
b=b+a1.charAt(i);
}
if(a1.equals(b))
{
System.out.println("PALINDROME");
}
else
{
System.out.println("NOT A PALINDROME");
}
break;
}
case 2:
{
System.out.println("Enter a number:");
a=sc.nextInt();
int d1=a;
while(a!=0)
{
rem=a%10;
rev=rev*10+rem;
a=a/10;
}
if(d1==rev)
{
System.out.println("PALINDROME");
}
else
{
System.out.println("NOT A PALINDROME");
}
break;
}
default:
{
System.out.println("Executed");
}
}
}
catch(Exception e)
{
System.out.print("Enter only numbers");
}
}
}