java examples _25 determine whether the palindrome!

1  / * 25 procedure [25] seeking palindrome 
 2  Title: a 5-digit, it determines that it is not a palindrome. That 12321 is a palindrome, the same bits and ten thousand, ten and one thousand identical.
3  * / 
. 4  
5  / * Analysis
 6  *% with the first and / or the separation of five digits, and then form a new five digits, if the new 5-digit number equal to the original, output Yes, whether the person NO
 . 7  * * / 
. 8  
. 9  
10  Package Homework;
 . 11  
12 is  Import java.util.InputMismatchException;
 13 is  Import java.util.Scanner;
 14  
15  public  class _25 {
 16  
. 17      public  static  void main (String [] args) {
 18 is          int0 = X ;
 . 19          // from the keyboard to give a 5-digit positive integer 
20 is          the while ( to true ) {
 21 is              System.out.println ( "Please enter a positive integer 5:" );
 22 is              the try {
 23 is                  // obtained from the keyboard a positive integer 
24                  Scanner SC = new new Scanner (the System.in);
 25                  X = sc.nextInt ();
 26 is                  iF ((X> = 10000) & (X <= 99999)) // determines whether the number of bits within 5 positive integer 
27                      BREAK ;
 28              } the catch (a InputMismatchException E) { // capture input exception
29                  System.out.println ( "Input Error:" + e.toString ());
 30              }
 31 is  
32          }
 33 is          // declaration n1, n2, and respectively denote the number of newly generated 5 digit 
34 is          int N1 = X, 0 = N2 ;
 35          the while (X> 0 ) {
 36              N2 = N2 * 10 + (X 10% );
 37 [              X = X / 10 ;
 38 is  //             System.out.println ( "X:" + X + "\ T "+" N2: "+ N2);    // test 
39          }
 40          IF (N1 == N2) {
 41 is              System.out.println (" Yes "! );
42         }
43         else {
44             System.out.println("no!");
45         }
46 
47     }
48 
49 }

 

Guess you like

Origin www.cnblogs.com/scwyqin/p/12313263.html