数字回文(java实现)
package Statement;
import java. util. Scanner;
public class Number {
@SuppressWarnings ( "resource" )
public static void main ( String[ ] args) {
int number= 0 , d1, d2, d3, d4, d5;
System. out. println ( "输入一个1~99999之间的数:" ) ;
number= new Scanner ( System. in) . nextInt ( ) ;
if ( number>= 1 && number <= 99999 ) {
d5= number/ 10000 ;
d4= ( number% 10000 ) / 1000 ;
d3= ( number% 1000 ) / 100 ;
d2= ( number% 100 ) / 10 ;
d1= number% 10 ;
if ( d5!= 0 ) {
System. out. println ( number+ "是五位数!" ) ;
if ( d5== d1 && d2== d4)
System. out. println ( number+ "是回文!" ) ;
else
System. out. println ( number+ "不是回文!" ) ;
} else if ( d4!= 0 ) {
System. out. println ( number+ "是四位数!" ) ;
if ( d4== d1 && d3== d4)
System. out. println ( number+ "是回文!" ) ;
else
System. out. println ( number+ "不是回文!" ) ;
} else if ( d3!= 0 ) {
System. out. println ( number+ "是三位数!" ) ;
if ( d3== d1)
System. out. println ( number+ "是回文!" ) ;
else
System. out. println ( number+ "不是回文!" ) ;
} else if ( d2!= 0 ) {
System. out. println ( number+ "是二位数!" ) ;
if ( d2== d1)
System. out. println ( number+ "是回文!" ) ;
else
System. out. println ( number+ "不是回文!" ) ;
} else if ( d1!= 0 ) {
System. out. println ( number+ "是一位数!" ) ;
System. out. println ( number+ "是回文!" ) ;
}
} else
System. out. println ( "\n" + number+ "不在1~9999之间!" ) ;
}
}