File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- class PalindromeExample {
2- public static void main (String args []){
3- int r ,sum =0 ,temp ;
4- int n =454 ;//It is the number variable to be checked for palindrome
5-
6- temp =n ;
7- while (n >0 ){
8- r =n %10 ; //getting remainder
9- sum =(sum *10 )+r ;
10- n =n /10 ;
11- }
12- if (temp ==sum )
13- System .out .println ("palindrome number " );
14- else
15- System .out .println ("not palindrome" );
16- }
1+
2+ import java .util .Scanner ;
3+ class Palindrome
4+ {
5+ public static void main (String args [])
6+ {
7+ String original , reverse = "" ; // Objects of String class
8+ Scanner sc = new Scanner (System .in );
9+ System .out .println ("Enter a string" );
10+ original = sc .nextLine ();
11+ int length = original .length ();
12+ for ( int i = length - 1 ; i >= 0 ; i -- )
13+ reverse = reverse + original .charAt (i );
14+ if (original .equals (reverse ))
15+ System .out .println ("Enter string is palindrome." );
16+ else
17+ System .out .println ("Enter string is not a palindrome." );
18+ }
19+ }
20+ class PalindromeExample {
21+ public static void main (String args []){
22+ int r ,sum =0 ,temp ;
23+ int n =454 ;//It is the number variable to be checked for palindrome
24+
25+ temp =n ;
26+ while (n >0 ){
27+ r =n %10 ; //getting remainder
28+ sum =(sum *10 )+r ;
29+ n =n /10 ;
30+ }
31+ if (temp ==sum )
32+ System .out .println ("palindrome number " );
33+ else
34+ System .out .println ("not palindrome" );
35+ }
1736}
You can’t perform that action at this time.
0 commit comments