好学IT学院:IT信息技术分享交流平台
标签:Java  来源:www.hxw.red  作者:本站整理  发布时间:2009-07-31  ★★★加入收藏〗〖手机版
摘要:关于java代码与编程的综合应用135、继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?答:父类:package test;public class FatherClass public FatherClass() Syste……

 
148、将一个键盘输入的数字转化成中文输出(例如:输入1234567,输出:一百二拾三万四千五百六拾七),请用java语言编一段程序实现!

public class Reader {
  private String strNum;
  private String strNumChFormat;
  private String strNumTemp;
  private int intNumLen;
  private String strBegin;
  public Reader(String strNum) {
  this.strNum = strNum;
  }

public boolean check(String strNum) {
  boolean valid = false;
  
  if (strNum.substring(0,1).equals("0")){
   this.strNum = strNum.substring(1);
  }
  try {
    new Double(strNum);
    valid = true;
  } catch (NumberFormatException ex) {
    System.out.println("Bad number format!");
  }
  return valid;
  }

public void init() {
  strNumChFormat = "";
  intNumLen = strNum.length();
  strNumTemp = strNum;
  strNumTemp = strNumTemp.replace('1', '一');
  strNumTemp = strNumTemp.replace('2', '二');
  strNumTemp = strNumTemp.replace('3', '三');
  strNumTemp = strNumTemp.replace('4', '四');
  strNumTemp = strNumTemp.replace('5', '五');
  strNumTemp = strNumTemp.replace('6', '六');
  strNumTemp = strNumTemp.replace('7', '七');
  strNumTemp = strNumTemp.replace('8', '八');
  strNumTemp = strNumTemp.replace('9', '九');
  strNumTemp = strNumTemp.replace('0', '零');
  strNumTemp = strNumTemp.replace('.', '点');
  strBegin = strNumTemp.substring(0, 1);
  }

public String readNum() {
  if (check(strNum)) {
    init();
    try {
      for (int i = 1, j = 1, k = 1; i < intNumLen; i++) {
        if (strNumTemp.charAt(intNumLen - 1) == '零' && i == 1) {
          strNumChFormat = "位";
        }
        else if (strNumTemp.charAt(intNumLen - i) == '零' && j == 1) {
          strNumChFormat = "位" + strNumChFormat;
        }
        else if (strNumTemp.charAt(intNumLen - i) == '点') {
          j = 1;
          k = 1;
          strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
          continue;
        }
        else {
          strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
        }
        if (strNumTemp.charAt(intNumLen - i - 1) != '位' &&
            strNumTemp.charAt(intNumLen - i - 1) != '零') {
          if (j == 1 && i < intNumLen) {
            strNumChFormat = '拾' + strNumChFormat;
          }
          else if (j == 2 && i < intNumLen) {
            strNumChFormat = '百' + strNumChFormat;
          }
          else if (j == 3 && i < intNumLen) {
            strNumChFormat = '千' + strNumChFormat;
          }
        }
        if (j == 4 && i < intNumLen) {
          j = 0;
        }
        if (k == 4 && i < intNumLen) {
          strNumChFormat = '万' + strNumChFormat;
        }
        else if (k == 8 && i < intNumLen) {
          k = 0;
          strNumChFormat = '亿' + strNumChFormat;
        }
        j++;
        k++;
      }
      while (strNumChFormat.indexOf("位") != -1) {
        strNumChFormat = strNumChFormat.replaceAll("位", " ");
      }
      if (strNumChFormat.substring(0, 2) == "一拾") {
        strNumChFormat = strNumChFormat.substring(1, strNumChFormat.length());
      }
      if (strNumChFormat.indexOf("点") >= 0) {
        String rebegin = strNumChFormat.substring(0,
            strNumChFormat.indexOf("点"));
        String relast = strNumChFormat.substring(strNumChFormat.indexOf("点"),
            strNumChFormat.length());
        for (int i = 1; i <= relast.length(); i++) {
          relast = relast.replaceAll("拾", "");
          relast = relast.replaceAll("百", "");
          relast = relast.replaceAll("千", "");
          relast = relast.replaceAll("万", "");
          relast = relast.replaceAll("亿", "");
        }
        strNumChFormat = rebegin + relast;
      }
    }
    catch (ArrayIndexOutOfBoundsException ex) {
      ex.printStackTrace();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    int off = strNumChFormat.indexOf("点");
    strNumChFormat = strBegin + strNumChFormat.substring(0);
  }
  else {
    strNumChFormat = "";
  }
  return strNumChFormat;
  }
  public static void main(String args[]) {
  try {
    String number = args[0].toString();
    System.out.println("The number is: " + number);
    Reader reader = new Reader(number);
    System.out.println("Output String: " + reader.readNum());
  }
  catch (Exception ex) {
    System.out.println("Please input like that: javac Reader <number></number>");
  }
  }
}

关于IE6中显示PNG图片不透明问题的解决方案
  下面主要收集整理了两种让IE6显示透明PNG图片的方法,供大家在实际应用的灵活参考(本站顶部的主频道条就是综合应用的效果):…
  • 好学触屏公众号虎力全开、杨帆起航!
  • 好学考试H5触屏版开放内测