Skip to content

Commit 4e434ed

Browse files
authored
Merge pull request ronijpandey#3 from atulim/atulim-patch-3
Shortened the program by very much extent
2 parents 78f434a + a460944 commit 4e434ed

1 file changed

Lines changed: 18 additions & 29 deletions

File tree

Palindrome_or_not.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,25 @@
33
Descritpion : A Palindrome number is a number that remains the same when its digits are reversed. Like 16461, for example: we take 121 and reverse it, after revers it is same as original number
44
*/
55

6+
/*
7+
This code is much shorter written in java
8+
*/
69
import java.util.Scanner;
710

8-
class P{
9-
10-
public static void main(String args[])
11+
class Palindrome_or_not
1112
{
12-
int n,x,i,number;
13-
14-
boolean f=true;
15-
16-
Scanner sc= new Scanner(System.in);
17-
18-
number = sc.nextInt();
19-
20-
String str = Integer.toString(number);
21-
22-
String strArr[] = str.split("");
23-
24-
x = str.length();
25-
n=x/2;
26-
for(i=0;i<n;i++)
27-
{
28-
if(strArr[i].compareTo(strArr[--x])!=0)
29-
{f=false;break;}
30-
}
31-
32-
if(f==true)
33-
System.out.print(str +" is palindrome ");
34-
35-
else
36-
System.out.print( str+" is not a palindrome");
13+
public static void main(Sting args[])
14+
{
15+
Scanner x = new Scanner(System.in);
16+
17+
String st=x.next();
18+
String w="";
19+
int i;
20+
for(i=0;i<st.length();i++)
21+
w=st.charAt(i)+w;
22+
if(st.compareTo(w)==0)
23+
System.out.prinltn("Number is Pallindrome");
24+
else
25+
System.out.println("Number is Not Pallindrome");
26+
}
3727
}
38-
}

0 commit comments

Comments
 (0)