zoukankan      html  css  js  c++  java
  • [program] ReverseDigits ( 即: 倒序输出int类型的数字,比如1792,输出为2971)


      Write a program named "ReverseDigits ", it generates the number that has the same digits in the reverse order, as illustrated by this sample run:

    ---------------------------------ReverseDigits 类---------------------------------

    package chapter4;

    import java.util.InputMismatchException;
    import java.util.Scanner;

    /*
     * 倒序输出int类型的数字,比如1792,输出为2971
     *
     * */


    public class ReverseDigits {

        int N=0;
        int subnum=0;
       
     public void run(){
          System.out.println("please input number  : ");
          Scanner input=new Scanner(System.in);
      
          try {
             int num=input.nextInt();
       
             while (num>0){
        
             subnum=num%10;
             num=num/10;
        
            N =(N+subnum)*10;   //算法的关键~
          }
       
             N =N/10;    //算法的关键
      
          System.out.println("the ReverseDigits is :"+ N);
       
          } catch(InputMismatchException e1){
         
             System.out.println("输入数据类型不符,应为int 类型");

          }
      
       }
     }

    --------------------------主函数调用--------------------------------

    package chapter4;

    public class main4 {

     /**
      * 主要运行<<the art and science of java>>第4章的练习题目
      */
     public static void main(String[] args) {

      ReverseDigits rev1=new ReverseDigits();
      rev1.run();

     }

    }

    不断的总结,才能不断的提高;不断的思考,才能不断的进步!
  • 相关阅读:
    hive metastore && hiveserver2 . 基本配置
    Flink HA 搭建坑
    protobuf 编译安装
    编译Hadoop 2.7.2支持压缩 转
    centos 6挂载磁盘
    python
    python之面向对象(一)
    python
    python-文件压缩和解压
    python-configparser模块
  • 原文地址:https://www.cnblogs.com/nzyjlr/p/1999061.html
Copyright © 2011-2022 走看看