Experimental code:
* * Copyright and Version Statement of the procedure * Copyright (c) 2011, Yantai University Computer College students * All rights reserved. * File name: Testnumber.java * Author: Zhang Zongjia * Completion Date: September 16, 2012 * Edition This number: v1.0 * Description of tasks and solutions * Problem Description: Write a Java application, the user from the keyboard to enter a 1~9999 between the number, the program will determine the number of the * is a few digits, and determine whether this number is a palindrome number. Palindrome number refers to the number of numbers contained in reverse order after the number * and the original number of the same, such as 12121, 3223 are palindrome number.
Code appended.
* Algorithm Description: * program Head of the annotation end */import Javax.swing.JOptionPane;
public class Testnumber {public static void main (String args[]) {loopnumber ();
} static void Loopnumber () {int number=0,d5,d4,d3,d2,d1; String Str=joptionpane.showinputdialog ("Enter a number from 1 to 99999");//The form of the dialog box Number=integer.parseint (str);//Convert if (nu Mber > 1 && number < 99999)//To determine the condition of number between 1 and 99999 {d5 = number/10000;//to calculate the highest Bit (million-bit) d5 d4 = number/1000% 10;//calculates number of thousands d4 d3 = number% 1000/100;
Number of hundred D3 d2=number% 100/10; D1=number% 10;
if (D5 > 0)//Judging number is a 5-digit condition {System.out.println (number+ "is 5 digits");
if (d5 = = D1 && D4 = = D2)//Judge number is the condition of palindrome numbers {System.out.println (number+ "is palindrome number");
else {System.out.println (number+ "not palindrome number"); } else if (d5 = 0 && d4 > 0)//Determine the number is a 4-digit condition {SYSTEM.O
Ut.println (number+ "is 4 digits");
if (D1 = = D4 && D2 = = D3)//Judge number is a palindrome of the conditional code {SYSTEM.OUT.PRINTLN (number+ "is palindrome number");
else {System.out.println (number+ "not palindrome number");
} else if (d5 = 0 && d4 = 0 && d3 > 0)//Determine number is a 3-digit condition {
System.out.println (number+ "is 3 digits");
if (D1 = = D3)//Judge number is the condition of palindrome numbers { System.out.println (number+ "is palindrome number");
else {System.out.println (number+ "not palindrome number");
} else if (d2!=0) {System.out.println (number+ "is 2 digits");
if (D1==D2) {System.out.println (number+ "is a palindrome number");
else {System.out.println (number+ "not palindrome number");
} else if (d1!=0) {System.out.println (number+ "is 1 digits");
System.out.println (number+ "is palindrome number");
} else {System.out.printf ("\n%d not between 1 and 99999", number); }
}
}
Experimental results:
1221 is a 4-digit number.
1221 is a palindrome number.