java的数组练习(小写变大写)_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java的数组练习(小写变大写)

java的数组练习(小写变大写)

 2014/5/27 12:15:26  JAVA_HOME117  程序员俱乐部  我要评论(0)
  • 摘要:packagecn.javass.hello.servletimpl.vo;importjava.util.Arrays;publicclassNumRmb{publicstaticvoidmain(String[]args){NumRmbnr=newNumRmb();System.out.println(Arrays.toString(nr.divide(2367.123)));System.out.println(nr.toHanStr("3423"));
  • 标签:数组 Java
class="java" name="code">
package cn.javass.hello.servletimpl.vo;

import java.util.Arrays;

public class NumRmb {
	public static void main(String[] args) {

		NumRmb nr = new NumRmb();
		System.out.println(Arrays.toString(nr.divide(2367.123)));
		System.out.println(nr.toHanStr("3423"));

	}

	private String[] hanArr = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌",
			"玖" };
	private String[] unitArr = { "拾", "佰", "仟" };

	private String[] divide(double num) {

		long zheng = (long) num;
		long xiao = Math.round((num - zheng) * 100);

		return new String[] { zheng + "", String.valueOf(xiao) };

	}

	private String toHanStr(String numStr) {
		String result = "";
		int numLen = numStr.length();

		for (int i = 0; i < numLen; i++) {
			int num = numStr.charAt(i) - 48;
                        //char型数字减去48就等于int数字
			if (i != numLen - 1 && num != 0) {
				result += hanArr[num] + unitArr[numLen - 2 - i];
			} else {
				result += hanArr[num];
			}

		}
		return result;

	}
}

发表评论
用户名: 匿名