zoukankan      html  css  js  c++  java
  • java判断回文数代码实例

    import java.util.Scanner;
    /*
     *  第三章 java运算符
     * 课后作业 判断回文数
     * 5.2.1  由用户输入一个整数,判断是不是回文数(完全对称的数),如果是 打印 true, 否则打印false
     * 提示:本题仅要求判断一个五位数是不是回文数
     * 			通过除法运算和求模运算符,可以分别求出一个五位数的每位上的值,然后进行比较。
     * Palindrome 回文数
     */
    public class zuoye0352 {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		System.out.println("输入要判断是否为回文数的数值:");
    		int i=sc.nextInt();
    		String str=""+i;
    		if(str.length()%2==0){
    			System.out.println(i+"不是回文数!"+str.length()%2);
    		}
    		//判断反转后 值是否相等 从而
    		else if(i==fanzhuan(i)){
    			System.out.println(i+"是回文数~");
    		}
    		else
    			System.out.println(i+"不是回文数!");
    	}
    	private static int fanzhuan(int input) {
    		int output = 0;//
    		while(input>0){
    			//output= output*10;
    			output=output*10+input%10;
    			input=input/10;
    
    		}		
    		return output;
    	}
    }


  • 相关阅读:
    Gerrit配置--用户配置
    repo+manifests+git方式管理安卓代码
    FLASH OTP
    Wireshark抓包分析TCP协议
    python 批量修改图片大小
    python 文件查找 glob
    python 统计单词个数
    python 图片上添加数字源代码
    python 删除文件和文件夹
    python 程序列表
  • 原文地址:https://www.cnblogs.com/aikongmeng/p/3697446.html
Copyright © 2011-2022 走看看