File tree Expand file tree Collapse file tree 1 file changed +29
-30
lines changed
Expand file tree Collapse file tree 1 file changed +29
-30
lines changed Original file line number Diff line number Diff line change 1- //To check whether Pallindrome or not
1+ //To check whether Palindrome or not
22import java .util .*;
3- class Pallindrome
4- {
5- public static void main (String a [])
6- {
7- int i ,flag =0 ;
8- Scanner sc = new Scanner (System .in );
9- System .out .println ("Enter the string to check whether palindrome or not" );
10- String s = sc .next ();
11- int n =s .length ();
12- char [] a1 = new char [n ];
13- a1 =s .toCharArray ();
14- System .out .println (a1 );
15- for (i =0 ;i <n -i ;i ++)
16- {
17- if (a1 [i ]==a1 [n -1 -i ])
18- {
19- continue ;
20- }
21- else
22- {
23- flag =1 ;
24- break ;
25- }
26- }
27- if (flag ==0 )
28- System .out .println ("The string is palindrome" );
29- else
30- System .out .println ("The string is not palindrome" );
31- }
3+
4+ class Palindrome {
5+ public static void main (String a []) {
6+ int i , flag = 0 ;
7+ Scanner sc = new Scanner (System .in );
8+
9+ System .out .println ("Enter the string to check whether palindrome or not" );
10+ String s = sc .next ();
11+ int n = s .length ();
12+
13+ char [] a1 = new char [n ];
14+ a1 = s .toCharArray ();
15+ System .out .println (a1 );
16+
17+ for (i = 0 ; i < n - i ; i ++) {
18+ if (a1 [i ] == a1 [n - 1 - i ]) {
19+ continue ;
20+ } else {
21+ flag = 1 ;
22+ break ;
23+ }
24+ }
25+
26+ if (flag == 0 )
27+ System .out .println ("The string is palindrome" );
28+ else
29+ System .out .println ("The string is not palindrome" );
30+ }
3231}
You can’t perform that action at this time.
0 commit comments