java程序设计算出回文数字源码
这道题会有个问题,先埋下伏笔,兄弟们可以思考下010这个数值。这里只能显示10是个回文数,输出的不是010是个回文数。package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("Enter three-digit integer:"); int number=input.nextInt(); int b0=number/100; int b1=number/10%10; int b2=number%10; if(b0==b2){ System.out.println(number+" "+"is a palindrome"); }else System.out.println(number+" "+"is not a palindrome"); } } 续上:改进了一下package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("Enter three-digit integer:"); String number=input.nextLine(); if(number.charAt(0)==number.charAt(2)){ System.out.println(number+" "+"is a palindrome"); }else System.out.println(number+" "+"is not a palindrome"); } }
页:
[1]