Determining whether a number is a palindrome palindrome or print a specific range.

Palindrome: Let n be an arbitrary natural number. The resulting n1 natural number equal to n if n digits of oppositely oriented, then n is a palindrome.

1  public  class PracticeDemo {
 2      / ** 
. 3       * @ Function: isPalindrome
 . 4       * @ the Description: determining whether a number is a palindrome number (a positive number with the read and read as anti).
5       * @ the Input: an integer
 6       * @ return_type: boolean
 7       * @ the Return: to determine whether the palindrome number of flowers (true and false)
 8       * @ Other: use knowledge to solve a string
 9       * February 2020 18:
 10        * 11:54:15 am
 . 11       * / 
12 is      public  static  Boolean isPalindrome ( int X)
 13 is      {
 14          string S = "" + X; // Java support string concatenation
15          for ( int I = 0; I <s.length () / 2; I ++ )
 16          {
 . 17              IF (! S.charAt (I) = s.charAt (s.length () -. 1-I)) // front and rear positions of the extracted string 
18 is              return  to false ;
 . 19          }
 20 is          return  to true ;
 21 is      }
 22 is      // above 
23 is      public  static  Boolean isPalindrome1 ( int X)
 24      {
 25         IF (X <0 )
 26 is         {
 27           return  to false;
 28         }
 29         int TEMP =. 1 ;
 30         int A = X;
 31 is         the while (A> = 10) // 1001 
32          {
 33 is            TEMP * = 10; // upper weight 
34 is            A / = 10; // to find the best pave weights 
35          }
 36       
37 [         the while (X = 0! ) 
 38 is          {
 39            IF (= 10% X X / TEMP!) // last and most significant bit comparator 
40             {
 41 is               return  to false ;
 42 is            }
 43 is            X = X TEMP% / 10; // X becomes the top removed and a last 
44 is            TEMP / = 100; // every removal of two numbers, reduced bit weight value 100 
45          }
 46 is         return  to true ; 
 47       }
 48     / ** 
49      * @ Function: PrintPalindrome
 50      * @ the Description: printing range into output palindrome
 51 is      * @ the input: two integers, x ~ y represents a range of
 52 is      * @ the output: x ~ y palindrome range of
 53      * @ return_type: void
 54      * @ the Return: void
 55      * @ Other: use of string
 56      * 2020, February 18:
 57      * 12:04:15 pm
58     * / 
59     public  static  void PrintPalindrome ( int X, int Y)
 60      {
 61 is        for ( int I = X; I <Y +. 1; I ++ ) 
 62 is         {   
 63 is           int IS =. 1; // number of flags or numbers M (in for a first front :) M 
64           String = L "" + I; 
 65           for ( int J = 0; J <l.length () / 2; J ++ )
 66           {
 67              IF ! (l.charAt (J) = l.charAt (l.length () - l- J))
 68              {
69                  IS = -1 ;
 70               // Continue M; M to jump directly at numeral 
71 is              }
 72           }
 73 is           IF (-1 =! IS)
 74              of System.out.print (I + "" );
 75        }
 76     }
 77   public  static  void main (String [] args) {
 78      Scanner iNPUT = new new Scanner (the System.in);
 79      System.out.println ( "Please enter the number of palindromic range requirement:" );
 80      int X = input.nextInt ();
 81      int Y = input.nextInt();
82     //System.out.println(isPalindrome(x));
83     //System.out.println(isPalindrome1(x));
84     PrintPalindrome(x,y);
85   }
86  }

 

Guess you like

Origin www.cnblogs.com/YangK123/p/12325669.html