概述
看到知乎上有人晒出了自己面腾讯的面经,有一道题目跟我碰到过的题目很像,突然想写写试一下;这道题目是:写金融行业交易金额小写转换为大写的方法,如1234元转换为壹仟贰佰叁拾肆圆。
我当时想起以前看递归算法时看到过的一个例子,依次输出一个整数的各位数字,写了如下几个版本,感觉挺有意思,贴出来。
package com.mjq.test1;
/**
* 测试 金融行业经常需要将交易金额转换为大写,如9999元 转换为 玖仟玖佰玖拾玖圆 需要写一个方法完成这个功能,想起看过一个递归的例子依次输出数字的每一位
* 但是我写出了如下几个版本,试分析哪个是正确的?
* @author Administrator
*
*/
public class test1 {
public static void main(String [] args)
{
convertor2(1234455666);
//System.out.println(1.2%0.1);
}
public static void convertor(int num)
{
if(num>10)
{
int a = num%10;
System.out.println("最低位是:"+a);
int b = num/10;
convertor(b);
}
else
{
System.out.println("最低位是:"+num);
}
}
public static void convertor1(int num)
{
if(num>10)
{
int a = num%10;
System.out.println("最低位是:"+a);
int b = num/10;
convertor1(b);
return;
}
System.out.println("最低位是:"+num);
}
public static void convertor2(int num)
{
if(num>10)
{
int a = num%10;
System.out.println("最低位是:"+a);
int b = num/10;
convertor1(b);
}
System.out.println("最低位是:"+num);
}
}
正确的方法,运行结果如下:
最后
以上就是勤奋发带为你收集整理的面试题目,金融行业交易金额小写转换为大写的方法,我写的几个版本的全部内容,希望文章能够帮你解决面试题目,金融行业交易金额小写转换为大写的方法,我写的几个版本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复