4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47.
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(\ this.strNum = strNum.substring(1); }
try {
new Double(strNum); valid = true;
} catch (NumberFormatException ex) {
System.out.println(\ }
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); }
?Copyleft;2008-10-01; by feeling. 16
48. 49. 50. 51. 52. public String readNum() { if (check(strNum)) { init(); try {
for (int i = 1, j = 1, k = 1; i < intNumLen; i++) {
零
53. if (strNumTemp.charAt(intNumLen - 1) == '' && i == 1) {
54. strNumChFormat = \位\
55. } else if (strNumTemp.charAt(intNumLen - i) == '' && j == 1) {
零
56. strNumChFormat = \位\
57. } else if (strNumTemp.charAt(intNumLen - i) == '点') {
58. j = 1; 59. k = 1;
60. strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
61. continue; 62. } else {
63. strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
64. } 65. if (strNumTemp.charAt(intNumLen - i - 1) != '' && strNumTemp.charAt(intNumLen - i - 1) != '零') {
66. if (j == 1 && i < intNumLen) {
67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85.
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++; }
位
?Copyleft;2008-10-01; by feeling. 17
86. while (strNumChFormat.indexOf(\位\87. strNumChFormat = strNumChFormat.replaceAll(\\
88. }
位
89. if (strNumChFormat.substring(0, 2) == \一拾\
90. strNumChFormat = strNumChFormat.substring(1, strNumChFormat.length());
91. }
92. 93.
if (strNumChFormat.indexOf(\点\
String rebegin = strNumChFormat.substring(0, strNumChF
ormat.indexOf(\点\
94. String relast = strNumChFormat.substring(strNumChFormat.indexOf(\点\
95. for (int i = 1; i <= relast.length(); i++) {
96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108.
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(); }
109. int off = strNumChFormat.indexOf(\点\
110. strNumChFormat = strBegin + strNumChFormat.substring(0);
111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122.
123. } catch (Exception ex) {
} else {
strNumChFormat = \ }
return strNumChFormat; }
public static void main(String args[]) { try {
String number = args[0].toString();
System.out.println(\ Reader reader = new Reader(number);
System.out.println(\
?Copyleft;2008-10-01; by feeling. 18
124. System.out.println(\number>\
125. } 126. } 127. } 3.现在输入n个数字,以逗号,分开;然后可选择升或者降序排序;按提交键就在另一页面显示按什么排序,结果为,提供reset
import java.util.*;
public class bycomma{
public static String[] splitStringByComma(String source){ if(source==null||source.trim().equals(\ return null;
StringTokenizer commaToker = new StringTokenizer(source,\ String[] result = new String[commaToker.countTokens()]; int i=0;
while(commaToker.hasMoreTokens()){ result[i] = commaToker.nextToken(); i++; }
return result; }
public static void main(String args[]){
String[] s = splitStringByComma(\ int[] ii = new int[s.length]; for(int i = 0;i Arrays.sort(ii); //asc for(int i=0;i for(int i=(s.length-1);i>=0;i--){ System.out.println(ii[i]); } } } 4、金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出。 package test.format; ?Copyleft;2008-10-01; by feeling. 19 import java.text.NumberFormat; import java.util.HashMap; public class SimpleMoneyFormat { public static final String EMPTY = \ public static final String ZERO = \零\ public static final String ONE = \壹\ public static final String TWO = \贰\ public static final String THREE = \叁\ public static final String FOUR = \肆\ public static final String FIVE = \伍\ public static final String SIX = \陆\ public static final String SEVEN = \柒\ public static final String EIGHT = \捌\ public static final String NINE = \玖\ public static final String TEN = \拾\ public static final String HUNDRED = \佰\ public static final String THOUSAND = \仟\ public static final String TEN_THOUSAND = \万\ public static final String HUNDRED_MILLION = \亿\ public static final String YUAN = \元\ public static final String JIAO = \角\ public static final String FEN = \分\ public static final String DOT = \ private static SimpleMoneyFormat formatter = null; private HashMap chineseNumberMap = new HashMap(); private HashMap chineseMoneyPattern = new HashMap(); private NumberFormat numberFormat = NumberFormat.getInstance(); private SimpleMoneyFormat() { numberFormat.setMaximumFractionDigits(4); numberFormat.setMinimumFractionDigits(2); numberFormat.setGroupingUsed(false); chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ chineseNumberMap.put(\ ?Copyleft;2008-10-01; by feeling. 20 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Java面试题集(最全版)(4)在线全文阅读。
相关推荐: