7-4 sdut-JAVA-Palindromic Number
分数 16
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
"A palindromic number or numeral palindrome is a number that remains the same when its digits
are reversed." Examples of palindromic numbers are 1234321, 777, 1 and 66. You are required to write a Java application program that determines whether or not a number supplied by the end user is
palindromic.
Input Specification:
Input a integer number.
Output Specification:
display the result whether or not a number supplied by the end user is
palindromic.
Sample Input:
12321
Sample Output:
Number input:12321 Number in reverse:12321 Number is palindromic
Sample Input:
12334
Sample Output:
Number input:12334 Number in reverse:43321 Number is not palindromic
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main1 { public static void main(String [] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); String a=""; a=String.valueOf(n); String b=""; int i; for(i=a.length()-1;i>=0;i--) { b+=a.charAt(i); } if(a.equals(b)) { System.out.println("Number input:"+n); System.out.println("Number in reverse:"+b); System.out.println("Number is palindromic"); } else { System.out.println("Number input:"+n); System.out.println("Number in reverse:"+b); System.out.println("Number is not palindromic"); } } }